0

I keep getting a syntax error, unexpected end-of-input, despite checking the code, and even after removing the code and running it the problem seems to not be solved.here is the code :

class BookingsController < ApplicationController

before_filter :authenticate_user!

def new
    @booking = Booking.new
end

def create
    @booking = current_user.booking.create(booking_params)
    if @booking.save
        flash[:alert] = "You have now booked a date"
        redirect_to root_path
    else
        flash[:alert] = "Error:booking did not save"
        redirect_to root_path
        render 'new'
    end
end


def show
    @booking = Booking.find(params[:id])
end

def edit
    @booking = Booking.find(params[:id])

    unless @booking.user == current_user
        redirect_to root_path
    end
end

def update 
    @booking = Booking.find(params[:id])
    unless @booking.user == current_user
        redirect_to root_path

    if @booking.update_attributes(booking_params)   
        redirect_to root_path
        flash[:notice] = "You have edited your post"
    else
        render 'edit'
        flash[:alert] = "something went wrong"
    end
end

def destroy 
    @booking = Booking.find(params[:id])
    @booking.destroy
    redirect_to root_path
end 

private
def booking_params
    params.require(:booking).permit(:content)
end

end
0

3 Answers 3

2

you missed end keyword here

def update 
    @booking = Booking.find(params[:id])
    unless @booking.user == current_user
        redirect_to root_path
    end # <~~~ missed in your code
    if @booking.update_attributes(booking_params)   
        redirect_to root_path
        flash[:notice] = "You have edited your post"
    else
        render 'edit'
        flash[:alert] = "something went wrong"
    end
end
Sign up to request clarification or add additional context in comments.

1 Comment

Thank you!! It worked, I thought "unless" would be part of the "if and "else" statement and not need a separate end.
2

Bogus update method; you're missing an end of the current_user check.

Also redirect does not stop executing code, you need to return.

Comments

1

Actual error - missed end after unless condition.

You can even refactor your code like this

def update 
    @booking = Booking.find(params[:id])
    redirect_to root_path unless @booking.user == current_user
    if @booking.update_attributes(booking_params)   
        redirect_to root_path
        flash[:notice] = "You have edited your post"
    else
        render 'edit'
        flash[:alert] = "something went wrong"
    end
end

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.