Skip to content

Instantly share code, notes, and snippets.

@ohammersmith
Created April 17, 2009 20:41
Show Gist options
  • Select an option

  • Save ohammersmith/97244 to your computer and use it in GitHub Desktop.

Select an option

Save ohammersmith/97244 to your computer and use it in GitHub Desktop.
<h1>Custom form demo</h1>
<!-- maybe the real thing -->
<% form_tag(:action => "create") do %>
<% for question in @questions %>
<%= hidden_field_tag "responses[][#{question.id}][type]", question.q_type %>
<% if question.q_type == "checkbox" %>
Checkbox <br/>
<%= h question.question %> <br />
<% for option in question.options %>
<%= option %>
<%= check_box_tag "responses[][#{question.id}][answers][]", option %> <br />
<% end %>
<hr/>
<% end -%>
<% if question.q_type == "select" %>
Select <br/>
<%= h question.question %> <br />
<%= select_tag ("responses[][#{question.id}][answers][]", options_for_select(question.options) ) %>
<hr/>
<% end -%>
<% if question.q_type == "radio" %>
Radio <br/>
<%= h question.question %> <br />
<% for option in question.options %>
<%= option %>
<%= radio_button_tag "responses[][#{question.id}][answers][]", option %> <br />
<% end %>
<hr/>
<% end -%>
<% end %>
<%= submit_tag "Post" %>
<% end -%>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment