This error is coming when I am updating, I don't know why this error is coming
def update1
@user = User.find(params[:user])
if @user.update_attributes(user_params)
redirect to user_steps_path
else
render 'edit1'
end
end
private
def user_params
params.require(:user).permit(:fname, :lname, :email)
end
end
Parameters:
{"utf8"=>"✓",
"authenticity_token"=>"wY+llV4qot5xDsxp1JvaltvPdrZND7goaorBTh8Vteo=",
"user"=>"51",
"commit"=>"Update"}
Edit.html.erb
This is my edit form
<%= form_for :user do |f| %>
<div class="form-group">
<%= f.label :First_Name %><br />
<%= f.text_field :fname, :class=> 'form-control' %>
</div>
<div class="form-group">
<%= f.label :Last_Name %><br />
<%= f.text_field :lname, :class=> 'form-control' %>
</div>
<div class="form-group">
<%= f.label :Email_Address %><br />
<%= f.email_field :email, :class=> 'form-control' %>
</div>
<div class="button">
<%= f.submit 'Update' %>
</div>
</div>
<% end %>
please help me out on this...
Your code doesn't make sense in the form it is in now:
@user = User.find(params[:user])
if @user.update_attributes(user_params)
In the first line you assume params[:user] equals to id. In the second you assume it's a hash of attributes.
Anyway to fix the problem you need to modify your user_params
method, e.g.:
def user_params
if params[:user].is_a? String
params[:user]
else
params.require(:user).permit(:fname, :lname, :email)
end
end
Or change the way you pass id:
params = {"utf8"=>"✓",
"authenticity_token"=>"wY+llV4qot5xDsxp1JvaltvPdrZND7goaorBTh8Vteo=",
"user"=>{ "id" => "51" },
"commit"=>"Update"}
@user = User.find(params[:user][:id])
def user_params
params.require(:user).permit(:id, :fname, :lname, :email)
end
You have given same name(:user
) in update1 method and in user_params method.that's why it is giving error
def update1
@user = User.find(params[`:user`])
private
def user_params
params.require(`:user`).permit(:fname, :lname, :email)
end
Try to change the :user
(give some other name) in
@user = User.find(params[`:user`])
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With