Hi Everybody! As a newcomer to this list and to Rails per se I would like to to post my silly newbie questions ? be patient: 1. I''m not able to get rid of the welcome-aboard-screen. It says:> 3. Set up a default route and remove or rename this file > > Routes are setup in config/routes.rb.I''ve done the routing part ? at least I think I have! Now, as for the removing or renaming of *that* file: where on earth is it?!?! 2. I want to use session[:language] to save the current working language between requests. But whenever I mention the yet unassigned symbol of session Rails throughs an exception:> NoMethodError in ExpressionsController#list > > You have a nil object when you didn''t expect it! > You might have expected an instance of Array. > The error occured while evaluating nil.[]The method causing the error is> def get_language > session[:language] ||= Language.find(1) > endYour help is greatly appreciated! - Sebastian -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060621/82af4f2a/attachment.html
>1. I''m not able to get rid of the welcome-aboard-screen. It says: > 3. Set up a default route and remove or rename this file >> >> Routes are setup in config/routes.rb. > I''ve done the routing part ? at least I think I have! Now, as for the > removing or renaming of *that* file: where on earth is it?!?!Don''t feel bad! I just spent three days last week working on this!! The file they are referring to is /public/indx.html I simply renamed mine, then set up a default rout (map.connect '''', :controller => ''www'') and it worked like a charm! Not too sure about #2 at the moment... hope someone else can contribute there! HTH, -Luke -- Posted via http://www.ruby-forum.com/.
Sebastian Winkler wrote:>> You might have expected an instance of Array. >> The error occured while evaluating nil.[] > The method causing the error is >> def get_language >> session[:language] ||= Language.find(1) >> endtruth be told, i''m not really out of the class of Newbies, but my guess would be one of two..either you haven''t defined the session(or is it @session) in the right place(are you putting this in the appcontroller/..?) or the specified language (1) isn''t found in the model...if you aren''t going to use many languages, couldn''t you go like this: @session[:language] ||= ''english'' @session[:language] ||= ''spanish'' .. good luck either way, s -- Posted via http://www.ruby-forum.com/.
For #2:
Session access can only be done in a controller. It should work as a
method call, but just to be safe, go ahead and treat it as an i-var, and
put an @, as so:
By the way, just so you know, the Ruby Way is to have varname() and
varname=(), not get_varname(), set_varname()
def language
@session[:language] ||= Language.find(1)
end
Jason
Sebastian Winkler wrote:> Hi Everybody!
>
> As a newcomer to this list and to Rails per se I would like to to post
> my silly newbie questions ? be patient:
>
> 1. I''m not able to get rid of the welcome-aboard-screen. It says:
>> 3. Set up a default route and remove or rename this file
>>
>> Routes are setup in config/routes.rb.
> I''ve done the routing part ? at least I think I have! Now, as for
the
> removing or renaming of *that* file: where on earth is it?!?!
>
> 2. I want to use session[:language] to save the current working
> language between requests. But whenever I mention the yet unassigned
> symbol of session Rails throughs an exception:
>> NoMethodError in ExpressionsController#list
>>
>> You have a nil object when you didn''t expect it!
>> You might have expected an instance of Array.
>> The error occured while evaluating nil.[]
> The method causing the error is
>> def get_language
>> session[:language] ||= Language.find(1)
>> end
>
> Your help is greatly appreciated!
> - Sebastian
> ------------------------------------------------------------------------
>
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
> The file they are referring to is /public/indx.htmlThanks, Luke!! Murule, the declaration is in a subclass of ApplicationController where session[] should be accessible. Murule and Jason, I really think it should be session[], not @session []; it''s not an instance variable I''m trying to access? Strangely, I seem to have been able to temporarily overcome this error ? not knowing how, though. But now I have done some reorganizing within the controller and I''m faced with the same situation again. As always it''s probably something totally simple but easy to overlook for the beginner. - Sebastian P.S. Jason, you''re right the way the method is formulated should have been called just ''language''.
Well, this seems to be the solution: I was calling the method from the controller''s initialize method, at which point session apparently isn''t accessible yet. I moved the call to the before_filter and now it works. Thanks for your efforts, guys! - Sebastian On 22.06.2006, at 13:17, Sebastian Winkler wrote:> Strangely, I seem to have been able to temporarily overcome this > error ? not knowing how, though. But now I have done some > reorganizing within the controller and I''m faced with the same > situation again. > As always it''s probably something totally simple but easy to > overlook for the beginner.-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060622/f102c18b/attachment-0001.html