Mohammad Seif Mohammad Seif - 17 days ago 11
Ruby Question

How to get params from select form in rails

I have this code in my view:

<% select("post", "person_id", Person.all.collect {|p| [ p.name, p.id ] }, {include_blank: true }) %>


I want to get value of
post[:person_id]
from params.

When I am trying

@person_Select = params[:post[person_id]]


I am getting error.

Answer

You should use below way to get your params in controller:

@selected_person = params[:post][:person_id]