class Object
Public Instance Methods
create()
click to toggle source
# File lib/bookable/generators/bookable/templates/controllers/booking_controller.rb, line 15 def create @booking = Booking.new(params[:booking].permit(:<%=resource_name.singularize%>_id, :start_time, :length)) @booking.<%=resource_name.singularize%> = @<%=resource_name.singularize%> if @booking.save redirect_to <%=resource_name.singularize%>_bookings_path(@<%=resource_name.singularize%>, method: :get) else render 'new' end end def show @booking = Booking.find(params[:id]) end
destroy()
click to toggle source
# File lib/bookable/generators/bookable/templates/controllers/booking_controller.rb, line 29 def destroy @booking = Booking.find(params[:id]).destroy if @booking.destroy flash[:notice] = "Booking: #{@booking.start_time.strftime('%e %b %Y %H:%M%p')} to #{@booking.end_time.strftime('%e %b %Y %H:%M%p')} deleted" redirect_to <%=resource_name.singularize%>_bookings_path(@<%=resource_name.singularize%>) else render 'index' end end
edit()
click to toggle source
# File lib/bookable/generators/bookable/templates/controllers/booking_controller.rb, line 39 def edit @booking = Booking.find(params[:id]) end
find_(<%=resource_name.singularize%> if params[:<%=resource_name.singularize%>_id])
click to toggle source
# File lib/bookable/generators/bookable/templates/controllers/booking_controller.rb, line 71 def find_<%=resource_name.singularize%> if params[:<%=resource_name.singularize%>_id] @<%=resource_name.singularize%> = <%=resource_name_camelize.singularize%>.find_by_id(params[:<%=resource_name.singularize%>_id]) end
save(booking)
click to toggle source
# File lib/bookable/generators/bookable/templates/controllers/booking_controller.rb, line 62 def save booking if @booking.save flash[:notice] = 'booking added' redirect_to <%=resource_name.singularize%>_booking_path(@<%=resource_name.singularize%>, @booking) else render 'new' end end
update()
click to toggle source
# File lib/bookable/generators/bookable/templates/controllers/booking_controller.rb, line 43 def update @booking = Booking.find(params[:id]) # @booking.<%=resource_name%> = @<%=resource_name%> if @booking.update(params[:booking].permit(:<%=resource_name.singularize%>_id, :start_time, :length)) flash[:notice] = 'Your booking was updated succesfully' if request.xhr? render json: {status: :success}.to_json else redirect_to <%=resource_name.singularize%>_bookings_path(@<%=resource_name.singularize%>) end else render 'edit' end end