Best practices to handle routes for STI subclasses in rails

后端 未结 18 1288
面向向阳花
面向向阳花 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:03

    Here is a safe clean way to have it work in forms and throughout your application that we use.

    resources :districts
    resources :district_counties, controller: 'districts', type: 'County'
    resources :district_cities, controller: 'districts', type: 'City'
    

    Then I have in my form. The added piece for this is the as: :district.

    = form_for(@district, as: :district, html: { class: "form-horizontal",         role: "form" }) do |f|
    

    Hope this helps.

提交回复
热议问题