Mohammad Seif Mohammad Seif - 5 months ago 9
Ruby Question

How to use params in rails by select form

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