无法在ROR

时间:2016-01-10 18:21:30

标签: ruby-on-rails forms

我的表单中有一个选择选项,我知道这会阻止表单提交。我无法弄清楚为什么。以下是导致问题的代码段:

<%= f.select(:state_id, options_for_select(State.all.map {|p| [ p.home_state, p.id ]}), :label => "State", :class => "dropdown-menu")%>

以下是表格的其余部分:

<% provide(:title, 'New Profile') %>

<%= bootstrap_form_for(@profile) do |f| %>

<%= f.text_field :name, :autofocus => true, :placeholder => 'Name' %>
<%= f.number_field :age, :placeholder => 'Age' %>
<%= f.form_group :sex, label: { text: "Sex" } do %>
<br>
  <%= f.radio_button :sex, 'Male', label: "Male", inline: true %>
  <%= f.radio_button :sex, 'Female', label: "Female", inline: true %>
<% end %>

<%= f.text_field :city, :id => 'gmaps-input-address', :placeholder => "City" %>

<%= f.select(:state_id, options_for_select(State.all.map {|p| [ p.home_state, p.id ]}), :label => "State", :class => "dropdown-menu")%>

<%= f.submit "Submit", :class =>'btn btn-primary' %>


<% end %>

总是非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

如果有的话,你应该看一下collection_select帮助者:

<%= bootstrap_form_for(@profile) do |f| %>
    <%= f.text_field :name, autofocus: true, placeholder: 'Name' %>
    <%= f.number_field :age, placeholder: 'Age' %>
    <%= f.form_group :sex, label: { text: "Sex" } do %>
       <%= f.radio_button :sex, 'Male', label: "Male", inline: true %>
       <%= f.radio_button :sex, 'Female', label: "Female", inline: true %>
    <% end %>

    <%= f.text_field :city, :id => 'gmaps-input-address', placeholder: "City" %
    <%= f.collection_select :state_id, State.all, :home_state, :id, prompt: "State", class: "dropdown-menu")%>

    <%= f.submit "Submit", class: 'btn btn-primary' %>
<% end %>

您还希望发布您可能已收到的任何控制台日志。请记住,计算机是基于逻辑的,它们不是情绪化的,只有在出现错误时才会停止工作。你的工作就是找到错误并修复它,因此显示你的代码会对你的代码产生无限的帮助,而猜测并不是这样:)