What are Stro...
What are Stro...
Strong Parameters is a feature in Ruby on Rails that allows you to control and whitelist the parameters that are permitted for mass assignment. It helps prevent accidentally allowing users to update sensitive attributes or perform mass assignment attacks.
Here are the key points about Strong Parameters:
Strong Parameters allows you to explicitly define which parameters are permitted for mass assignment. This is done by specifying the allowed parameters in your controller actions.
def create
@user = User.new(user_params)
if @user.save
redirect_to @user
else
render :new
end
end
private
def user_params
params.require(:user).permit(:name, :email)
end
In the example above, the user_params
method whitelists the :name
and :email
parameters for mass assignment.
Strong Parameters also supports nested parameters....
senior
Gợi ý câu hỏi phỏng vấn
Chưa có bình luận nào