Can I do STI and still use polymorphic path helpers?

前端 未结 1 485
说谎
说谎 2021-02-05 18:11

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 U

相关标签:
1条回答
  • 2021-02-05 18:55

    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|
      ...
    
    0 讨论(0)
提交回复
热议问题