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.

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

junior

How Is Visibility Of Methods Changed In Ruby (encapsulation)?

junior

Explain what is a class library in Ruby?

middle

Can you explain the difference between ActiveSupport’s HashWithIndifferentAccess and Ruby’s Hash ?

Bình luận

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

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