[英]Rails:How can I get these check_boxes and radio buttons to show the data from the model?
[英]Rails : How can I get boolean data from radio button?
我有數據庫表“問題”,“答案”。(這兩個表已通過has_many,belongs_to和nested_form關系關聯。)
並且答案表中有user_answer(boolean,default'false')列。
我要這樣
但是我不知道該怎么辦。 這是輸入表格。
<h1><%= @survey.name %></h1>
<%= form_tag({:controller => "surveys", :action => "grading"}) do %>
<ol class="questions">
<% @survey.questions.each do |question| %>
<li>
<strong><%= question.content %></strong>
<ol class="checkbox">
<% question.answers.each do |answer| %>
<%= radio_button_tag(answer.user_answer) %>
<%= label("answer_".concat(answer.id.to_s).to_sym, answer.content) %>
<% end %>
</ol>
<hr />
</li>
<% end %>
</ol>
<div><%= submit_tag("Submit", :class => "submit") %></div>
當然,有一個錯誤。 radio_button_tag需要2個參數。 但是我不知道該怎么辦。 請告訴我。
在模型中聲明一個常量,例如:
STATUS = [['active', true], ['Inactive', false]]
並在視圖中使用選項進行選擇。
<%= f.select :status, options_for_select(User::STATUS) %>
有用的資源:
http://apidock.com/rails/ActionView/Helpers/FormTagHelper/radio_button_tag
http://apidock.com/rails/ActionView/Helpers/FormOptionsHelper/options_for_select
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.