儘管檢查了代碼,但我仍然收到語法錯誤,意外的輸入結束,甚至在刪除代碼並運行它之後,問題似乎無法解決。是代碼:獲取語法錯誤,意外的輸入結束
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
謝謝!!它起作用了,我認爲「除非」將成爲「if和else」聲明的一部分,並且不需要單獨結束。 – user3150377