简体   繁体   中英

My form does not show up in the view -Ruby on Rails?

I do not know why my form is not showing up in my views. I have a form and I am using the chosen-rails gem to allow choosing existing users and assign them a task. My form however does not show up in the views and I am not getting an error. I just don t know what s wrong. Here is my form:

<div class="invitations">
<%= form_tag assignments_path, method: :post do |f| %>
<div class="form-group">
<%= label_tag 'user_id', 'Choose Freelancer' %>
<%= f.association :user_id, 
              collection: User.all,
              include_blank: false,
              input_html: { class: 'chosen-select' }
%>
</div>
<%= submit_tag 'Assign', class: 'btn btn-primary' %>
<% end %>
<br>
</div>

Try this:

<div class="invitations">
 <%= form_tag assignments_path, method: :post do%>
   <div class="form-group">
    <%= label_tag 'user_id', 'Choose Freelancer' %>
    <%= collection_select(:user_id,User.all,:id,:name) %>
   </div>
 <%= submit_tag 'Assign', class: 'btn btn-primary' %>
<% end %>
<br>
</div>

form_tag helper方法块不带参数,因此您无法执行f.association您可能还希望将带有form-group的div移动到form标签上方,以便它包围实际的标签并设置其样式。

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM