jeudi 23 avril 2015

Add params in strong parameters

Lets say I have params like this:

def boat_params
   params
      .require(:boat)
      .permit(:message
              :alarm_en,
              :alarm_es,
              :alarm_sv)
end


What I try is basically shorten this code, with:

def boat_params
   params
      .require(:boat)
      .permit(:message).merge(alarm_params)
end

But for alarm_params I get errors when I tried:

def alarm_params
    params = {}
    ["en","es","sv"].each do |lang|
       params << "alarm_#{lang}" 
    end
    return params
end

What raised the error:

undefined method `<<' for {}:Hash

for: params << "alarm_#{lang}"


Next I tried it with an Array:

def alarm_params
    params = []
    ["en","es","sv"].each do |lang|
       params << "alarm_#{lang}" 
    end
    return params
end

What raised the error:

 undefined method `to_hash' 

In .merge(alarm_params)

What do I wrong? Thanks!

Aucun commentaire:

Enregistrer un commentaire