Saty Nos
2009-Aug-28 14:11 UTC
instance variables added in rails helpers are not available
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. -- Posted via http://www.ruby-forum.com/.
Frederick Cheung
2009-Aug-28 14:41 UTC
Re: instance variables added in rails helpers are not available
On Aug 28, 3:11 pm, Saty Nos <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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 in advance. > -- > Posted viahttp://www.ruby-forum.com/.
Saty Nos
2009-Aug-28 15:13 UTC
Re: instance variables added in rails helpers are not available
Frederick Cheung wrote:> On Aug 28, 3:11�pm, Saty Nos <rails-mailing-l...-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> 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) > > Fredthanks fred, using self.title = ''some title'' solved the problem -- Posted via http://www.ruby-forum.com/.