Rails render of partial and layout in controller

后端 未结 3 399
星月不相逢
星月不相逢 2021-01-04 10:04

I am overriding the create action of the devise Registrations Controller. I have two forms for signup, individual or company, a company has a field called company_form set t

3条回答
  •  清歌不尽
    2021-01-04 10:58

    Could you post your whole controller? Rails renders by default layout/application.html.erb if another layout is not specified.

    From the ror guides:

    Partial Layouts

    A partial can use its own layout file, just as a view can use a layout. For example, you might call a partial like this:

    <%= render partial: "link_area", layout: "graybar" %>
    

    This would look for a partial named _link_area.html.erb and render it using the layout _graybar.html.erb. Note that layouts for partials follow the same leading-underscore naming as regular partials, and are placed in the same folder with the partial that they belong to (not in the master layouts folder).

    Also note that explicitly specifying :partial is required when passing additional options such as :layout.

    So render partial: 'shared/company_signup_form', layout: 'layouts/application'is looking for layouts/_application.html.erb

提交回复
热议问题