Does the application controller have a related template?

Suppose I run

rails new proj1

I can do

rails generate abc def controller

and this creates, among other things. \ app \ views \ abc \ def.html.erb

And I can edit config.rb to say

get '/', to: 'abc#def'
or
root 'abc#def'

And this will load this template def.html.erbwhen I go tohttp://127.0.0.1:3000/

But I wonder if I can do this without creating this new controller. I am wondering if I can only go to the template using the application controller.

So, for example, I can edit .\app\controllers\application_controller.rband add

def a 
end 

then the application controller behaves like other controllers and tries to display the corresponding .html.erb file, for example. action 'a' will try to display a.html.erb? If so, I cannot find where I should place the a.html.erb file?

, , , rails generate controller blah a b c .

. , .

+4
1

:

routes.rb:

get '/', to: "application#root"

application_controller.rb

def root
end

///root.html.erb

hello world

localhost:3000 " "

- . , , .

+2
source

Source: https://habr.com/ru/post/1692154/


All Articles