Guest User

Untitled

a guest
Apr 21st, 2018
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. # STI Models
  2. class Question < AR::Base; end # should never be instantiated
  3. class YesNoQuestion < Question; end # should
  4. class TextQuestion < Question; end # should
  5. # etc...
  6.  
  7. # Form.rb (model)
  8. accepts_nested_attributes_for :questions # except I don't want to instantiate Question!
  9.  
  10. # forms/edit.html.erb (view)
  11. ...normal form_for |f|...
  12. <% f.fields_for :questions do |question_form| %>
  13. <%= question_form.select :type, { "Yes/No" => "YesNoQuestion", "Text" => "TextQuestion" } %>
  14. <% end %>
Add Comment
Please, Sign In to add comment