Can I do STI and still use polymorphic path helpers?
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|
...
Rails STI has_many STI children of one type
I ended up finding a solution:
I need to specify the class_name in has_many like so
has_many :C, :foreign_key => :parent_id, class_name: 'C::C1'
Related Topics
Overriding a Module Method from a Gem in Rails
How to Clear the Terminal in Ruby
How to Group by Count in Array Without Using Loop
What Is a Regex to Match a String Not At the End of a Line
Set Utf-8 as Default String Encoding in Heroku
How to Use CSS with a Ruby on Rails Application
Using Rvm on Ubuntu 12.04 to Use Rails. the Program 'Rails' Is Currently Not Installed
How to Split a String to Get All the Substrings by Ruby
How Do Rvm and Rbenv Actually Work
Rails4 Unknown Encoding Name - Cp720
Rails Browser Detection Methods
How to Read Lines of a File in Ruby
How to Implement a Short Url Like the Urls in Twitter
How to Define Action With Simple Form For
Idiomatic Object Creation in Ruby