Câu hỏi phỏng vấn Ruby on Rails
Câu hỏi

What are Stro...

Câu trả lời

Strong Parameters in Ruby on Rails

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:

1. Whitelisting 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.

ruby Copy
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.

2. Nested Parameters

Strong Parameters also supports nested parameters....

senior

senior

Gợi ý câu hỏi phỏng vấn

middle

Explain what is Interpolation in Ruby?

junior

How Many Types Of Associations Relationships Does A Model Have?

middle

How should you use nested layouts?

Bình luận

Chưa có bình luận nào

Chưa có bình luận nào