# Changing \<head\> in a view

**URL:** <https://www.ruby-forum.com/t/changing-head-in-a-view/150563>\
**Category:** Rails\
**Created:** [October 9, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/changing-head-in-a-view/150563 "2008-10-09T23:05:20Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![HansCz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@HansCz](https://www.ruby-forum.com/u/HansCz)\
**Post date:** [October 9, 2008, 11:05pm UTC](https://www.ruby-forum.com/t/changing-head-in-a-view/150563/1 "2008-10-09T23:05:20Z")

</div>

Given an application layout like

 Test \<%= stylesheet\_link\_tag 'test.css' %\>

```
<%= javascript_include_tag 'some_js', :cache => true, :charset =>

```

‘utf8’ %\>

 \<%= yield %\> 

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.

---

<div class="post-metadata">

**Author:** ![HansCz](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/h/3d9bf3/32.png) [@HansCz](https://www.ruby-forum.com/u/HansCz)\
**Post date:** [October 9, 2008, 11:07pm UTC](https://www.ruby-forum.com/t/changing-head-in-a-view/150563/2 "2008-10-09T23:07:41Z")

</div>

Yep, using a content\_for call:

[http://www.inthetail.com/2008/4/24/ruby-on-rails-content\_for](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](mailto: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/](http://alinhavado.wordpress.com/) (pt-br) | [http://blog.codevader.com/](http://blog.codevader.com/)  
(en)  
João Pessoa, PB, +55 83 8867-7208
