Rails : How can I get boolean data from radio button? -
i have db tables 'question', 'answer'.(those 2 tables has been related has_many , belongs_to, , nested_form relationship.)
and there user_answer(boolean, default 'false') column in answer table.
i want make this.
- if user check radio button, user_answer change 'true' value.
- then i'll compare value in correct column in answer table,
- and i'll save result in is_correct column in question table.
but don't know how can do. input form.
<h1><%= @survey.name %></h1> <%= form_tag({:controller => "surveys", :action => "grading"}) %> <ol class="questions"> <% @survey.questions.each |question| %> <li> <strong><%= question.content %></strong> <ol class="checkbox"> <% question.answers.each |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> of course, there error. radio_button_tag need 2 parameters. don't know how can do. please let me know.
declare constant in model such as:
status = [['active', true], ['inactive', false]] and use options select in views.
<%= f.select :status, options_for_select(user::status) %> useful resources:
http://apidock.com/rails/actionview/helpers/formtaghelper/radio_button_tag
http://apidock.com/rails/actionview/helpers/formoptionshelper/options_for_select
Comments
Post a Comment