I''m having problems with class variables.. I have a class: class Content::ApplicantsController < ApplicationController layout "mylayout" @@tab = "mystring" [... the rest is standard scaffold-created stuff ...] and a layout (mylayout.rhtml): [...] <title><%= @@tab.capitalize %></title> [...] And I keep getting this error: uninitialized class variable @@tab in ActionView::Base::CompiledTemplates I''ve searched the net and come up dry. Ruby docs say I''m supposed to initialize class variables before I can use them but I''d assume that the `` = "mystring" `` would count as initializing it... -- Posted via http://www.ruby-forum.com/.
i think it is deep in the language, that you actually have to initialize
it via the initialize(arg/args) definition, although i am not definately
sure...
what about if you do this inside the class -
def initialize(str)
@str = str
end
@@tab = Classinstancevar.new("mystring")
will this work?
--
Posted via http://www.ruby-forum.com/.
Gabriel wrote:>I''m having problems with class variables.. I have a class: > >class Content::ApplicantsController < ApplicationController > layout "mylayout" > @@tab = "mystring" > [... the rest is standard scaffold-created stuff ...] > > >and a layout (mylayout.rhtml): > >[...] ><title><%= @@tab.capitalize %></title> >[...] > > >And I keep getting this error: > > >uninitialized class variable @@tab in >ActionView::Base::CompiledTemplates > >I''ve searched the net and come up dry. Ruby docs say I''m supposed to >initialize class variables before I can use them but I''d assume that the >`` = "mystring" `` would count as initializing it... > > >I think rails only copies instance variables from the controller objects to the view objects. -- Jack Christensen jackc@hylesanderson.edu
cooperg@myrealbox.com
2006-Jul-06 19:43 UTC
[Rails] Re: Class variables in templates/layouts
shai wrote:> what about if you do this inside the class - > def initialize(str) > @str = str > end > @@tab = Classinstancevar.new("mystring") > will this work?I''m not sure... I don''t think I get the chance to initialize a Controller manually.... Jack Christensen wrote:> I think rails only copies instance variables from the controller objects > to the view objects.Hm... What''s the best way to get a variable to the view for all actions if you can''t do it with a class variable? -- Posted via http://www.ruby-forum.com/.
I''m using a DATE field, for my primary key table.
but When
@mymodel = Feeding.new(@params[''mymodel''])
@mymodel.save
it ignores the param "ID" and try to put the default value of the
empty
field, wicht is "0000-00-00"
what is wrong?
tks
cooperg-YSGFQ8SKJZVDPfheJLI6IQ@public.gmane.org escreveu:
shai wrote:
what about if you do this inside the class -
def initialize(str)
@str = str
end
@@tab = Classinstancevar.new("mystring")
will this work?
I''m not sure... I don''t think I get the chance to initialize a
Controller manually....
Jack Christensen wrote:
I think rails only copies instance variables from the controller objects
to the view objects.
Hm... What''s the best way to get a variable to the view for all actions
if you can''t do it with a class variable?
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails
dblack@wobblini.net
2006-Jul-06 19:58 UTC
[Rails] Re: Class variables in templates/layouts
Hi -- On Thu, 6 Jul 2006, cooperg@myrealbox.com wrote:> shai wrote: >> what about if you do this inside the class - >> def initialize(str) >> @str = str >> end >> @@tab = Classinstancevar.new("mystring") >> will this work? > > > I''m not sure... I don''t think I get the chance to initialize a > Controller manually.... > > > Jack Christensen wrote: >> I think rails only copies instance variables from the controller objects >> to the view objects. > > > Hm... What''s the best way to get a variable to the view for all actions > if you can''t do it with a class variable?Put it in an instance variable that you initialize in a before_filter in application.rb. David -- "To fully realize the potential of Rails, it''s crucial that you take the time to fully understand Ruby--and with "Ruby for Rails" David has provided just what you need to help you achieve that goal." -- DAVID HEINEMEIER HANSSON, in the foreword to RUBY FOR RAILS. Complete foreword & sample chapters at http://www.manning.com/black!
cooperg@myrealbox.com
2006-Jul-06 21:15 UTC
[Rails] Re: Re: Class variables in templates/layouts
> Put it in an instance variable that you initialize in a before_filter > in application.rb. >Yeah I just came to that conclusion... I''d rather have a class variable. ;) -- Posted via http://www.ruby-forum.com/.