问题
My error page tells me "param is missing or the value is empty: user" and references my user_params private method and my create action as the culprits. It also shows that all the params I'm passing in are getting picked up by the create post.
abbreviated Controller:
def new
@user = User.new
end
def create
@user = User.new(user_params)
@user.save
redirect_to @user
end
private
def set_user
@user = User.find(params[:id])
end
def user_params
params.require(:user).permit(:first_name, :last_name, :email)
end
My form_tag that initiates the create post:
= form_tag @user do
.form-group
= label_tag :first_name, nil, class: 'col-md-2'
= text_field_tag :first_name, nil, class: 'col-md-3'
%br
.form-group
= label_tag :last_name, nil, class: 'col-md-2'
= text_field_tag :last_name, nil, class: 'col-md-3'
%br
.form-group
= label_tag :email, nil, class: 'col-md-2'
= email_field_tag :email, nil, class: 'col-md-3'
%br
.actions.form-group
= submit_tag 'Submit', class: 'btn btn-primary col-md-offset-2'
回答1:
Change:
= form_tag @user do
to
= form_for @user do |f|
And then all label_tag to f.label, text_field_tag to f.text_field, email_field_tag to f.email_field and finally submit_tag to f.submit. Remove all nils and all should work.
来源:https://stackoverflow.com/questions/26737978/actioncontrollerparametermissing-in-userscontrollercreate