Skip to content

Instantly share code, notes, and snippets.

@lorennorman
Created October 27, 2009 19:17
Show Gist options
  • Save lorennorman/219855 to your computer and use it in GitHub Desktop.
Save lorennorman/219855 to your computer and use it in GitHub Desktop.
# STI Models
class Question < AR::Base; end # should never be instantiated
class YesNoQuestion < Question; end # should
class TextQuestion < Question; end # should
# etc...
# Form.rb (model)
accepts_nested_attributes_for :questions # except I don't want to instantiate Question!
# forms/edit.html.erb (view)
...normal form_for |f|...
<% f.fields_for :questions do |question_form| %>
<%= question_form.select :type, { "Yes/No" => "YesNoQuestion", "Text" => "TextQuestion" } %>
<% end %>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment