문제

For rails 4 Strong Parameters I need to access two of the fields. How can I do that?

 def branch_params
   params.require(:branch).permit( :equal_number, :equal_main_branch_number, 
                                   :history, :inquiry_email, :internal_notes,
                                   :is_main_branch, :main_branch_number, :name,                
                                   :number,:region_id, :serving )
 end

I understand this part. Strong Parameters

def create
  @branch = Branch.new(branch_params)
end

Now I need to pass two of the fields to pass into a method.

 format_branch_number(:equal_number, :equal_main_branch_number)
도움이 되었습니까?

해결책

According to docs

Action Controller parameters are forbidden to be used in Active Model mass assignments until they have been whitelisted

what means, you cant use them to create AR object, but you can still use your params to do some stuff with them, so you can simply format_branch_number(params[:equal_number], params[:equal_main_branch_number])

다른 팁

try this:

format_branch_number(params[:branch][:equal_number], params[:branch][:equal_main_branch_number])
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top