I'm doing a dropdown field that gets it's values from another controller, I defined it like this:
def dropdown
@tarefa_list = Tarefa.all.map { |c| [c.Numero] [c.Resumo]}
end
and call it like this:
<%= f.select :Tarefa, @tarefa_list, {}, {class: "dropdown"} %>
Numero being a integer and Resumo being a string
the error im getting when I try to view the form:
no implicit conversion of String into Integer
How about:
@tarefa_list = Tarefa.all.map { |c| [c.Numero, c.Resumo] }
And then:
<%= f.select :Tarefa do %>
<% @tarefa_list.each do |c| -%>
<%= content_tag(:option, c.first, value: c.last) %>
<% end %>
<% end %>
It's not pretty but we can start from here.
(based on: http://guides.rubyonrails.org/form_helpers.html#select-boxes-for-dealing-with-models )
Btw I think the no implicit conversion of String into Integer
comes from the fact that expression [c.Numero] [c.Resumo]
tries to get the c.Resumo
element of an array defined of [c.Numero]
So something like [1,2,3]['a']
As you can imagine it won't work.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.