Ruby on Rails
Monday, January 15, 2018
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 sI go to http://127.0.0.1:3000 and I see the default template view .\app\views\abc\def.html.erbBut 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.erbis<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="bDkNOUtlUKmlo1uzMRTqz CUCzBLX0q4/ " />0NM8OfSXccoHocfYeZNFe+ TsR8a4wvZhKakKRlXbU+ NjWsnp4hNfXg== <link rel="stylesheet" media="all" href="/assets/abc.self- e3b0c44298fc1c149afbf4c8996fb9 " data-turbolinks-track="reload" />2427ae41e4649b934ca495991b7852 b855.css?body=1 <link rel="stylesheet" media="all" href="/assets/application. self- " data-turbolinks-track="reload" />f0d704deea029cf000697e2c0181ec 173a1b474645466ed843eb5ee7bb21 5794.css?body=1 <script src="/assets/rails-ujs.self- 817d9a8cb641f7125060cb18fefada " data-turbolinks-track="reload"3f35339170767c4e003105f92d4c20 4e39.js?body=1 > </script><script src="/assets/turbolinks.self- 2db6ec539b9190f75e1d477b305df5 " data-turbolinks-track="reload"3d12904d5cafdd47c7ffd91ba25cbe c128.js?body=1 > </script><script src="/assets/abc.self- 877aef30ae1b040ab8a3aba4e3e309 " data-turbolinks-track="reload"a11d7f2612f44dde450b5c157aa5f9 5c05.js?body=1 > </script><script src="/assets/action_cable. self- " data-turbolinks-track="reload"69fddfcddf4fdef9828648f9330d6c e108b93b82b0b8d3affffc59a11485 3451.js?body=1 > </script><script src="/assets/cable.self- 8484513823f404ed0c0f039f75243b " data-turbolinks-track="reload"fdede7af7919dda65f2e6639125244 3ce9.js?body=1 > </script><script src="/assets/application.self- eba3cb53a585a0960ade5a8cb94253 " data-turbolinks-track="reload"892706bb20e3f12097a13463b1f12a 4528.js?body=1 > </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+unsubscribe@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.
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment