I am using Single Table Inheritance and have comments on all the subclasses. I am only using 1 controller for all the different STI types. When the form_for helper generates a URL for a subtype it tries to use a helper for the subtype, but I want it to use the helper for the parent.
This is the error I get:
undefined method `subclasstypename_comments_path' for #<ActionView::Base:0x41ef27c>
The path helper it 'should' use is
parentclasstypename_comments_path
Yep, just use AR::Base#becomes
.
Say your base class is Account
, which is subclassed to GuestAccount
and LoginAccount
.
@account.is_a? LoginAccount? #=> true
Then you can just do a
form_for [@account.becomes(Account), @comment] do |f|
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With