Best practices to handle routes for STI subclasses in rails

后端 未结 18 1307
面向向阳花
面向向阳花 2020-11-30 16:25

My Rails views and controllers are littered with redirect_to, link_to, and form_for method calls. Sometimes link_to and <

18条回答
  •  被撕碎了的回忆
    2020-11-30 17:01

    You can create method that returns dummy Parent object for routing purpouse

    class Person < ActiveRecord::Base      
      def routing_object
        Person.new(id: id)
      end
    end
    

    and then simply call form_for @employee.routing_object which without type will return Person class object

提交回复
热议问题