In Rails 4 for some reason layouts-templates from the app/views/layouts. folder are not rendered standardly app/views/layouts. For example, the template app/views/layouts/application.html.erb not rendered. It only saves the render layout:"application" parameter in the controller actions ... this is terribly inconvenient. Is there any way to tell Rails that I NEED to render default templates ALWAYS?

thank

UPD:

1) I created a new project and the controller "hello" 2) Routing:

 root "hello#index" resources :hello do get :pops, on: :collection end 

3) controller actions:

 class HelloController < ApplicationController def index render text: "Works" end def show render text: "Show" end def pops #render text: "Pops", layout: "application" // работает render text: "Pops" // не работает подгрузка layouts end end 

4) app / views / layouts / application.html.erb:

  <!DOCTYPE html> <html> <head> <title>Ror</title> <%= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true %> <%= javascript_include_tag "application", "data-turbolinks-track" => true %> <%= csrf_meta_tags %> </head> <body> <%= yield %> </body> </html> 

5) when you go to the URL "hello / pops" - the template is not loaded.

  • It seems to me that you are not saying something. Quite by chance you don't have layout layout false in application_controller.rb? Well, or in the controller itself? - Chad
  • Chad, I think I did not quite understand the question. Layout is simply not rendered with a standard generated project via Rails console. - AseN
  • one
    app / views / layout ** s ** / application.html.erb? - Vetal4eg
  • I just made rails new proj, created a Hello test controller with action index. Launched localhost: 3000 / hello / index. And I clearly see that application.html.erb is rendered, as always. Can you upload your project in a zip format somewhere on the file sharing service so that we all can take a look? - Stanislav Pankevich 6:51 pm
  • @ Vetal4eg, I just made a typo. @Stanislaw Pankevich, did you test on Rails 4, in a UNIX environment? The answer is updated. - AseN

2 answers 2

In this case, it should not be rendered with a layout. you specify the command render text: "..."

It seems to me that you need to create views for the controller's actions, and not specify the render directly.

...

  touch app/views/hello/show.html.erb 

...

 def show end 

As written here :

By default, if you use the current layout. If you want the current layout, you need to add the layout: true option.

  • And, here it is, what is the matter. So, when using render text: current layout is not used. Well, thanks - I didn't know that. - AseN
  • Well, actually, it is logical. Render text should be used for ajax, for example, but if you want something more complicated, it is a bad idea to drag the view functionality into the controller. - Chad
  • one
    @ Chad, for now this is a test application. The render text: constructs were used as stubs. And so, of course, dragging the "display" into a "controller" is not MVC. - AseN

and your partials start at "_" ??? so <% = render "layouts / pratial"%> should work