# Default page and session\[\]

**URL:** <https://www.ruby-forum.com/t/default-page-and-session/64020>\
**Category:** Rails\
**Created:** [June 21, 2006, 1:21pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020 "2006-06-21T13:21:15Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sebastian\_Winkler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sebastian\_Winkler](https://www.ruby-forum.com/u/Sebastian_Winkler)\
**Post date:** [June 21, 2006, 1:21pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020/1 "2006-06-21T13:21:15Z")

</div>

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:

> 1. 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?!?!

1. 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

---

<div class="post-metadata">

**Author:** ![Sebastian\_Winkler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sebastian\_Winkler](https://www.ruby-forum.com/u/Sebastian_Winkler)\
**Post date:** [June 21, 2006, 1:27pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020/2 "2006-06-21T13:27:58Z")

</div>

> 1. I’m not able to get rid of the welcome-aboard-screen. It says:
> 2. 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

---

<div class="post-metadata">

**Author:** ![Sebastian\_Winkler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sebastian\_Winkler](https://www.ruby-forum.com/u/Sebastian_Winkler)\
**Post date:** [June 21, 2006, 2:14pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020/3 "2006-06-21T14:14:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sebastian\_Winkler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sebastian\_Winkler](https://www.ruby-forum.com/u/Sebastian_Winkler)\
**Post date:** [June 21, 2006, 3:23pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020/4 "2006-06-21T15:23:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Sebastian\_Winkler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sebastian\_Winkler](https://www.ruby-forum.com/u/Sebastian_Winkler)\
**Post date:** [June 22, 2006, 2:19pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020/5 "2006-06-22T14:19:41Z")

</div>

> 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  
removed\_email\_address@domain.invalid  
[http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

---

<div class="post-metadata">

**Author:** ![Sebastian\_Winkler](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/s/c0e974/32.png) [@Sebastian\_Winkler](https://www.ruby-forum.com/u/Sebastian_Winkler)\
**Post date:** [June 22, 2006, 3:12pm UTC](https://www.ruby-forum.com/t/default-page-and-session/64020/6 "2006-06-22T15:12:33Z")

</div>

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
