Rails: Render a View (not a partial) From Within a View

前端 未结 4 1325
一生所求
一生所求 2021-02-05 00:30

I have a controller that responds to both html and js. The html view renders the whole page (including the header and footer), while the <

4条回答
  •  花落未央
    2021-02-05 00:51

    This is not a good practice as you can see by the comments. Rails have the concepts of view, partial and layout. That said, the view is the only one you should keep using only once. So my suggestions are:

    1. If you feel that more than one extra view could be rendered inside your current view, you are most likely looking for a layout
    2. If you feel that one of your views should be rendered in many pages, you are looking for a partial
    3. If this view should render only one extra view inside it, and that view should only be rendered inside the current view, you can pick any of the above or none of it - that's it, go with a single file

提交回复
热议问题