I use /app/views/layouts/application.html.erb <html> <head> <%= yield :head %> </head> <body> <%= yield %> </body> </html>
/app/views/foo/bar.html.erb <% content_for :head do %> <title>A simple page</title> <% end %> <p>Hello, Rails!</p> This way I can add "'meta descriptions" and "meta keywords" to individual pages As Hassan mentioned http://guides.rubyonrails.org/layouts_and_rendering.html#using-the-content-for-method HTH John On Saturday, January 13, 2018 at 7:18:23 PM UTC-5, Robert Phillips wrote: > > I can't set the title of a page no matter what I have tried to put in my > .html.erb file > > > >rails new testblah > > >bundle install <-- not necessary here but anyway. > > >rails generate controller abc def > > > rails s > > I go to http://127.0.0.1:3000 and I see the default template view > .\app\views\abc\def.html.erb > > But even when I put <title>asdf</title> it doesn't change the title. > Even if I do > <html><head><title>asdf</title></head><body></body></html> > > it doesn't change the title. > > If I go to the rendered HTML of the page, I can see what it's doing.. > > Suppose my .\app\views\abc\def.html.erb > is > > <html> > <head><title>aaaaa</title></head> > <body></body> > </html> > > What gets rendered is this > > > <!DOCTYPE html> > <html> > <head> > <title>Test15</title> > <meta name="csrf-param" content="authenticity_token" /> > <meta name="csrf-token" content=" > bDkNOUtlUKmlo1uzMRTqzCUCzBLX0q4/0NM8OfSXccoHocfYeZNFe+TsR8a4wvZhKakKRlXbU+NjWsnp4hNfXg==" > > /> > > <link rel="stylesheet" media="all" href=" > /assets/abc.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1 > > <http://127.0.0.1:3000/assets/abc.self-e3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855.css?body=1>" > > data-turbolinks-track="reload" /> > <link rel="stylesheet" media="all" href=" > /assets/application.self-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css?body=1 > > <http://127.0.0.1:3000/assets/application.self-f0d704deea029cf000697e2c0181ec173a1b474645466ed843eb5ee7bb215794.css?body=1>" > > data-turbolinks-track="reload" /> > <script src=" > /assets/rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1 > > <http://127.0.0.1:3000/assets/rails-ujs.self-817d9a8cb641f7125060cb18fefada3f35339170767c4e003105f92d4c204e39.js?body=1>" > > data-turbolinks-track="reload"></script> > <script src=" > /assets/turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1 > > <http://127.0.0.1:3000/assets/turbolinks.self-2db6ec539b9190f75e1d477b305df53d12904d5cafdd47c7ffd91ba25cbec128.js?body=1>" > > data-turbolinks-track="reload"></script> > <script src=" > /assets/abc.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1 > > <http://127.0.0.1:3000/assets/abc.self-877aef30ae1b040ab8a3aba4e3e309a11d7f2612f44dde450b5c157aa5f95c05.js?body=1>" > > data-turbolinks-track="reload"></script> > <script src=" > /assets/action_cable.self-69fddfcddf4fdef9828648f9330d6ce108b93b82b0b8d3affffc59a114853451.js?body=1 > > <http://127.0.0.1:3000/assets/action_cable.self-69fddfcddf4fdef9828648f9330d6ce108b93b82b0b8d3affffc59a114853451.js?body=1>" > > data-turbolinks-track="reload"></script> > <script src=" > /assets/cable.self-8484513823f404ed0c0f039f75243bfdede7af7919dda65f2e66391252443ce9.js?body=1 > > <http://127.0.0.1:3000/assets/cable.self-8484513823f404ed0c0f039f75243bfdede7af7919dda65f2e66391252443ce9.js?body=1>" > > data-turbolinks-track="reload"></script> > <script src=" > /assets/application.self-eba3cb53a585a0960ade5a8cb94253892706bb20e3f12097a13463b1f12a4528.js?body=1 > > <http://127.0.0.1:3000/assets/application.self-eba3cb53a585a0960ade5a8cb94253892706bb20e3f12097a13463b1f12a4528.js?body=1>" > > data-turbolinks-track="reload"></script> > </head> > > <body> > <html> > <head><title>aaaaa</title></head> > <body></body> > </html> > </body> > </html> > > So, what it is doing is rails is taking its own template then it dumps my > template into its <body></body> > > So the title isn't getting set > > > -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscr...@googlegroups.com. To post to this group, send email to rubyonrails-talk@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/ce5640ea-d7a9-434b-89a0-c2de46e7a825%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.