Forum: Ruby on Rails Changing <head> in a view

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
HansCz (Guest)
on 2008-10-10 01:05
(Received via mailing list)
Given an application layout like

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://
www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
  <head>
    <meta http-equiv="Content-type" content="text/html;
charset=utf-8">
    <title>Test</title>
    <%= stylesheet_link_tag 'test.css' %>

    <%= javascript_include_tag 'some_js', :cache => true, :charset =>
'utf8' %>
  </head>
  <body>
    <%= yield %>
  </body>
</html>

and a controller, say

app/controllers/root_controller.rb:
class RootController < ApplicationController
  def index

  end
end

and a view file
app/views/root/index.html.erb

is it then possible to include a javascript file in the head section
of the resulting html, which is exclusive to the RootController's
index view?

Forgive me if you find this question trivial. I'm learning.
Maurício L. (Guest)
on 2008-10-10 01:07
(Received via mailing list)
Yep, using a content_for call:

http://www.inthetail.com/2008/4/24/ruby-on-rails-content_for

On Thu, Oct 9, 2008 at 4:20 PM, HansCz <removed_email_address@domain.invalid>
wrote:
>    <%= stylesheet_link_tag 'test.css' %>
>
> is it then possible to include a javascript file in the head section
> of the resulting html, which is exclusive to the RootController's
> index view?
>
> Forgive me if you find this question trivial. I'm learning.
>
> >
>



--
Maurício Linhares
http://alinhavado.wordpress.com/ (pt-br) | http://blog.codevader.com/
(en)
João Pessoa, PB, +55 83 8867-7208
This topic is locked and can not be replied to.