reactor
reactor

Reputation: 1941

why changes to layout application.html.erb view does not show on new Rails 6 app

Upon scaffolding a new Rails 6 app, I see the Yay! You’re on Rails! page. When making changes to application.html.erb, I'm not seeing the changes being reflected. I was wondering how to fix this.

Upvotes: 1

Views: 631

Answers (1)

jean182
jean182

Reputation: 3515

Because that is a static page.

What happens is that the yay you're in rails is a static page that is located on the rails gem, you can check that by looking through the logs of your server, mine for example is located here /Users/jean/.rvm/gems/ruby-2.6.3/gems/railties-6.0.2.2/lib/rails/templates/rails/welcome/index.html.erb enter image description here

In order to override you need to create a default root page in your routes.rb with the respective controller and view. That will use your application.html.erb as the default template.

For example you can create a home controller

rails g controller Home index

That will generate a bunch of files including the view file and the controller file, now you have to go to your routes, remove the route generated and add this:

root 'home#index'

Now if you start the server again you will be able to see the correct layout (application.html.erb) that you changed plus the content of the newly generated index.html.erb located in app/views/home.

Upvotes: 1

Related Questions