# Instance variables added in rails helpers are not available

**URL:** <https://www.ruby-forum.com/t/instance-variables-added-in-rails-helpers-are-not-available/174556>\
**Category:** Rails\
**Created:** [August 28, 2009, 4:11pm UTC](https://www.ruby-forum.com/t/instance-variables-added-in-rails-helpers-are-not-available/174556 "2009-08-28T16:11:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [August 28, 2009, 4:11pm UTC](https://www.ruby-forum.com/t/instance-variables-added-in-rails-helpers-are-not-available/174556/1 "2009-08-28T16:11:33Z")

</div>

I am trying to add some instance variables in helpers like the  
following:

module ApplicationHelper  
def title=(title)  
@title = title  
end

def title  
@title  
end  
end

and when I assign title in views/pages/index.html.erb like the  
following:

\<% title = ‘Listing Pages’ %\>

and try to show it in the views/layouts/application.html.erb like the  
following:

\<%= title %\>

it is showing as ‘’ and after some debugging, looks like @title is not  
being set.

Why are the instance variables added in the helpers not available in the  
views (templates)?

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [August 28, 2009, 4:53pm UTC](https://www.ruby-forum.com/t/instance-variables-added-in-rails-helpers-are-not-available/174556/2 "2009-08-28T16:53:48Z")

</div>

On Aug 28, 3:11 pm, Saty N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> \<%= title %\>
> 
> it is showing as ‘’ and after some debugging, looks like @title is not  
> being set.
> 
> Why are the instance variables added in the helpers not available in the  
> views (templates)?

because you didn;t create an instance variable. you just created a  
local variable called title (your title= method was never called)

Fred

---

<div class="post-metadata">

**Author:** ![satynos](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/e9bcb4/32.png) [@satynos](https://www.ruby-forum.com/u/satynos)\
**Post date:** [August 28, 2009, 5:13pm UTC](https://www.ruby-forum.com/t/instance-variables-added-in-rails-helpers-are-not-available/174556/3 "2009-08-28T17:13:16Z")

</div>

Frederick C. wrote:

> On Aug 28, 3:11ï¿½pm, Saty N. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:
> 
> > \<%= title %\>
> > 
> > it is showing as ‘’ and after some debugging, looks like @title is not  
> > being set.
> > 
> > Why are the instance variables added in the helpers not available in the  
> > views (templates)?
> 
> because you didn;t create an instance variable. you just created a  
> local variable called title (your title= method was never called)
> 
> Fred

thanks fred, using self.title = ‘some title’ solved the problem
