I've been working through "Agile Web Development with Rails" and have come across an issue.
I've been having issues with saving/retrieving data selected from a drop down menu. I have possible payment methods stored in a database table, and I have a drop down menu to select the desired payment method.
<div class="field">
<%= f.label :payment_type_id %><br>
<%= f.select :payment_type_id, options_from_collection_for_select(@payment_types,:id,:method), prompt: 'Select Payment Method'%>
</div>
My "create" action in the Orders controller
def create
@order = Order.new(order_params)
@order.add_line_items_from_cart(current_cart)
respond_to do |format|
if @order.save
Cart.destroy(session[:cart_id])
session[:cart_id] = nil
OrderNotifier.received(@order).deliver
format.html { redirect_to store_url, notice: 'Order has been placed' }
Everything gets saved apart from the payment_type_id foreign key, I know this because I've looked in the tables.
Any help would be greatly appreciated.
Thanks.
ActionController::Parametersin your log after submitting the formrequire/permitmethod. in this case it looks like it is namedorder_params- if you haven't included a field in that, then it will never be saved. If you can include your copy of that in your question, it'd help us to see if that's the case.require/permitmethod and indeed:payment_type_idwas not there. I put it in and it has solved my issue. I'm still very new to this language, thank you.