ruby - Rails - params not saving to database -


i'm building events app using rails , trying grips booking confirmation process. @ moment mvc seems on place.

here's new booking form free events purely requires quantity of spaces user requires -

new.html.erb

<%= simple_form_for [@event, @booking], id: "new_booking" |form| %>     <% if @booking.errors.any? %>         <h2><%= pluralize(@booking.errors.count, "error") %> prevented booking saving:</h2>         <ul>             <% @booking.errors.full_messages.each |message| %>                 <li><%= message %></li>             <% end %>         </ul>     <% end %>        <div class="form-group">         <p>please confirm number of spaces wish reserve event.</p>         <%= form.input :quantity, class: "form-control" %>     </div>        <p> free event. no payment required.</p>      <div class="panel-footer">          <%= form.submit :submit, label: 'confirm booking', class: "btn btn-primary" %>  <% end %>  </div>    

and here's controller code -

bookings_controller.rb

before_action :find_booking, only: [:show, :update] before_action :find_event, only: [:show, :update] before_action :authenticate_user!    def new     @event = event.find(params[:event_id])     @booking = @event.bookings.new(quantity: params[:quantity])     @booking.user = current_user end  def create     @event = event.find(params[:event_id])     @booking = @event.bookings.new(booking_params)     @booking.user = current_user      if @booking.paid_booking         flash[:success] = "your place on our event has been booked"         @booking.update_attributes!(booking_number: "mama" + '- ' + securerandom.hex(4).upcase)         redirect_to event_booking_path(@event, @booking)     else         flash[:error] = "booking unsuccessful"         render "new"     end end  def free_booking     if @booking.free_booking         @booking.update_attributes!(booking_number: "mama" + '- ' + securerandom.hex(4).upcase)         redirect_to event_booking_path(@event, @booking)     else         flash[:error] = "booking unsuccessful"         render "new"     end end  def show     @event = event.find(params[:event_id])     @booking = booking.find_by(booking_number: params[:booking_number]) end  def update     if @booking.save         redirect_to event_booking_path(@event, @booking) , notice: "booking updated!"     else         render 'new'     end end  private  def booking_params     params.require(:booking).permit(:stripe_token, :booking_number, :quantity, :event_id, :stripe_charge_id, :total_amount) end  def find_booking     @booking = booking.find_by(booking_number: params[:booking_number]) end  def find_event     @event = event.find(params[:event_id]) end 

when check booking on console, params being saved event_id , user_id - quantity not saved free bookings saved paid bookings. also, booking confirmation show view has following attributes included -

<%= @event.title %> <%= @booking.quantity %> <%= @booking.booking_number %> 

of these 3 attributes, event.title shows on page, other 2 don't show @ all. i'm stumped how or why happening. appreciate if can see i'm not able to.


Comments

Popular posts from this blog

account - Script error login visual studio DefaultLogin_PCore.js -

xcode - CocoaPod Storyboard error: -