From what I understand...
- If you have a
form_for @model
,params[:model]
is available when the form is submitted. Furthermore, if the form has 2 attributesattr1
andattr2
,params[:model][:attr1]
andparams[:model][:attr2]
are available when the form is submitted. - In Rails 4, you're supposed to write a method
model_params
that saysparams.require(:model).permit(:attr1, :attr2)
. - You'd then use
model_params
like so:Model.new(model_params)
.
However, what do you do if you only need one of the fields from the form? Like if you only needed params[:model][:attr1]
?
Example:
def create
@user = User.new(user_params)
if @user.save
# need access to params[:user][:password] here
redirect_to root_url, :notice => "Signed up!"
else
render :new
end
end
private
def user_params
params.require(:user).permit(:email, :password, :password_confirmation)
end