Hi, I am trying to access the value of :plate_qty but to no avail. I used the select_tag to define the variable :plate_qty.

The select_tag is defined in show.html.erb The value is accessed in line_items.controller.rb as shown below: show.html.erb: <br> <h1> <strong><%= @meal.name %><strong> </h1> <p> <%= @meal.description %> </p> <div class="jumbotron"> <div style="float:right;"> <%= select_tag(:plate_qty, options_for_select([['2 Plates', 2], ['4 Plates', 4], ['6 Plates', 6]], 2 )) %> <%= button_to 'Add to Cart', line_items_path(meal_id: @meal), class: "btn btn-primary btn-lg" %> </div> <div style="clear:both;"></div> <%= image_tag(@meal.image_url) %> </div> line_items_controller.rb: def create meal = Meal.find(params[:meal_id]) @line_item = @cart.add_product(meal.id) if params[:plate_qty].blank? @line_item.quantity = 6 else @line_item.quantity = params[:plate_qty] end It is returning a blank field.

Posted over 5 years ago by mark francisco
Posted about 5 years ago by Alex Yang

Mark, sorry for the delay on this one. Did you make sure to authorize :plate_qty as a permitted parameter in your controller?

0
Posted about 5 years ago by mark francisco

Yes, I did. If I hardcode the plate_qty it
works eg, <%= button_to 'Add to Cart', line_items_path(meal_id: @meal, plate_qty: 4), class: "btn btn-primary btn-lg" %> . plate_qty is passed to the controller with the value 4. I am completely befuddled.

0
Posted about 5 years ago by Alex Yang

Seems like your line_items_path in your original post doesn't contain this plate_qty parameter. That's the reason why it's not being passed.

0
Posted about 5 years ago by mark francisco

here is the issue, even when i pass the plate_qty parameter (button_to 'Add to Cart', line_items_path(meal_id: @meal, plate_qty: @meal), class: "btn btn-primary btn-lg", the value of plate_qty is now set to the value of meal_id. I retrieve the value of plate_qty using params[:plate_qty]

0
Posted about 5 years ago by Alex Yang

Are you sure that isn't an issue of how you've defined @meal? If you replace '@meal' with 4, what does params[:plate_qty] equal?

0
Posted about 5 years ago by mark francisco

It will equal to 4.

0
Posted about 5 years ago by Alex Yang

That's good - that narrows down the problem to how you've defined @meal. Double-check that it's being set to the object or value that you think it is.

0
Posted about 5 years ago by mark francisco

Everything is set accordingly in the @meal object with the exception of plate_qty.

0
Posted about 5 years ago by Alex Yang

Can you send me a link to your GitHub repository? I'll take a look.

0
Posted about 5 years ago by mark francisco

github.com/markmf/craftedplates
Thx!

0
Posted about 5 years ago by Alex Yang

Mark, a couple things. First, in your line_items_controller.rb, you are using 'meal' instead of '@meal'. Second, I'm not seeing your plate_qty code in views/line_items/show.html.erb. (However, I think you are missing a </p> there).

It would really help if you could be more specific about where everything is located. I've been flipping through your files trying to find your code and it's been pretty inefficient...

0