mardi 5 juillet 2016

How to correctly get values from two similar selects?

I need to get values from two similar selects in order to create an object.

So on my view I added two select dropdowns:

<%= select_tag "type_1", @types.map { |a| [a.id, a.name] } %>, prompt: 'Choose type'
<%= select_tag "type_2", @types.map { |a| [a.id, a.name] } %>, prompt: 'Choose type'

so that when I click on them, the following params are generated:

job =>
  {
    "type_1" => "1",
    "type_2" => "2"
  }

How can I merge them to have the only one type parameter?

Because this would look very stupid

def job_param
  params.require(:job).permit(:type_1, :type_2)
end

Aucun commentaire:

Enregistrer un commentaire