Ruby on Rails 4
I am passing a hidden value from my form.
<%= f.hidden_field :applied_program, :value => @applied_program.id %>
This is what is posted:
"applied_program"=>"891"} ...
ActiveRecord::RecordNotFound (Couldn't find AppliedProgram with 'id'={"applied_program"=>"891"})
I am trying to update attributes of the applied program in my controller.
I don't know how to assign the parameter to the record. This is what I am trying, but it can't find it based on the parameters passed.
I also tried passing just @applied_program without the .id but then I have the same problem finding it with the Object information. :/
@applied_program = AppliedProgram.find(applied_program_params)
The controller white list:
def applied_program_params
params.require(:payment).permit(:applied_program)
end
Try this
@applied_program = AppliedProgram.find(payment_params[:applied_program])
def payment_params
params.require(:payment).permit(:applied_program)
end
Your data will be passed like below from the form to the controller
{:permit => {:applied_program => 891}}
UPDATE:
applied_program_id = payment_params.delete(:applied_program)
@payment = Payment.new(payment_params)
@applied_program = AppliedProgram.find(applied_program_id)
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments