Domanda

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)
È stato utile?

Soluzione

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])

Altri suggerimenti

try this:

format_branch_number(params[:branch][:equal_number], params[:branch][:equal_main_branch_number])
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top