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
on 2006-06-21 13:21
on 2006-06-21 13:27
>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
on 2006-06-21 14:14
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) >> end truth 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
on 2006-06-21 15:23
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
on 2006-06-22 14:19
> The file they are referring to is /public/indx.html
Thanks, 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'._______________________________________________
Rails mailing list
Rails@lists.rubyonrails.org
http://lists.rubyonrails.org/mailman/listinfo/rails
on 2006-06-22 15:12
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
Please log in before posting. Registration is free and takes only a minute.
Existing account
(Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
Log in with Google account | Log in with Yahoo account
No account? Register here.