# Instance variables in templates

**URL:** <https://www.ruby-forum.com/t/instance-variables-in-templates/65411>\
**Category:** Rails\
**Created:** [August 18, 2006, 12:42am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411 "2006-08-18T00:42:34Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 12:42am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/1 "2006-08-18T00:42:34Z")

</div>

Hey all,

Well… hmm… feeling pretty stupid here…

For some reason my controller instance variables are not displaying  
in my templates. I’ve boiled it down to this test case.

class Rss::FilmController \< ApplicationController

def display  
@time = Time.now  
end

end

and the template:

 Is This Ever Going To Work 

it is now \<%= @time %\>

that’s it!

When I hit that with the browser all I get is the html? I can put  
ruby in the template and that works fine but nothing from the  
controller? This is basically the same as the code right from  
chapter 4 of the agile web dev book. I must be missing something  
terribly obvious.

That’s running under webrick, when I run from Apache all I get is  
“Rails application failed to start properly” error. From what I can  
tell that should all be configured correctly too. If anyone has  
idea’s (don’t think they are related, but I guess you never know)  
on that one that would be great too!

Thanks in advance!  
Tim

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 12:54am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/2 "2006-08-18T00:54:35Z")

</div>

On 8/17/06, Tim McIntyre [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> @time = Time.now  
>   
> terribly obvious.  
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Tim,

Normally you would simply put

\<%= @time.to\_s %\>

in the template. Then this template gets included in you layout  
(probably application.rhtml). Try that as a first step.

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 1:00am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/3 "2006-08-18T01:00:36Z")

</div>

Already tried that and no go!

Thanks for the response though Zack… any other ideas?

Tim

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 1:15am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/4 "2006-08-18T01:15:37Z")

</div>

Hey

Yeah, did all that too. Any ruby code I put directly in the template  
works fine it’s just that I get nothing from the controller even  
though it is obviously detecting the display method.

HELP HELP HELP!

Thanks again!  
Tim

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 2:03am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/5 "2006-08-18T02:03:40Z")

</div>

Help save a life… please!

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 1:06am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/6 "2006-08-18T01:06:37Z")

</div>

On 8/17/06, Tim McIntyre [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > > ```
> > > </body>
> > > 
> > > ```
> > > 
> > > That’s running under webrick, when I run from Apache all I get is  
> > > [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Tim,

Make sure your display.rhtml template is being called by adding:

It is \<%= Time.now.to\_s %\>

Refresh the page a few times and the value should change. Maybe it’s  
a caching thing. Also I would clear the brower cache, delete all  
session files (rake tmp:clear), restart ./script/server, AND close and  
reopen your browser.

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 7:55am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/7 "2006-08-18T07:55:44Z")

</div>

what are your files called? what url are you using?

Max

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 2:51am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/8 "2006-08-18T02:51:42Z")

</div>

Apparently rails chokes a bit on controller methods named “display”.  
I don’t know if this is a bug or if I missed some bit of  
documentation or ???

Here is my test case:

class Rss::FilmController \< ApplicationController

def test  
@time = Time.now  
end

def display  
@time = Time.now  
end

end

Then two identical templates just like so:

 Is This Ever Going To Work 

The time is \<%= @time %\>

localhost/rss/film/display does not work… the html displays but  
@time does not

localhost/rss/film/test works perfectly… with @time and all

Anyone have any thoughts on this???

Thanks!  
Tim

---

<div class="post-metadata">

**Author:** ![Tim\_McIntyre](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/7bcc69/32.png) [@Tim\_McIntyre](https://www.ruby-forum.com/u/Tim_McIntyre)\
**Post date:** [August 18, 2006, 8:52am UTC](https://www.ruby-forum.com/t/instance-variables-in-templates/65411/9 "2006-08-18T08:52:49Z")

</div>

Hey Max,

Thanks for the reply… I found the problem but it still seems  
weird. I started another thread with the subject “Bug? was -  
instance variables in templates” but here it is again:

Must be overriding a display method in app controller or something…  
seems that it should be documented though?

Apparently rails chokes a bit on controller methods named “display”.  
I don’t know if this is a bug or if I missed some bit of  
documentation or ???

Here is my test case:

class Rss::FilmController \< ApplicationController

def test  
@time = Time.now  
end

def display  
@time = Time.now  
end

end

Then two identical templates just like so:

 Is This Ever Going To Work 

The time is \<%= @time %\>

localhost/rss/film/display does not work… the html displays but  
@time does not

localhost/rss/film/test works perfectly… with @time and all

Anyone have any thoughts on this???

Thanks!  
Tim
