# \* Please Help - Session problem \*

**URL:** <https://www.ruby-forum.com/t/please-help-session-problem/175098>\
**Category:** Rails\
**Created:** [September 7, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/please-help-session-problem/175098 "2009-09-07T23:41:53Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [September 7, 2009, 11:41pm UTC](https://www.ruby-forum.com/t/please-help-session-problem/175098/1 "2009-09-07T23:41:53Z")

</div>

Hi There,

I am setting a session, whilst following the rails-space tutorial.

When i hit register, I can see there is a new row inserted to the  
sessions table, but now - for some reason, I don’t get the flash  
message as before:

My user controller looks like this:

def register  
@title = “Register”  
if request.post? and params[:user]  
@user = User.new(params[:user])  
if @user.save  
session[:user\_id] = @user.id  
flash[:notice] = “User ‘#{@user.screen\_name}’ created!”  
redirect\_to :action =\> “index”, :controller =\> “user”  
end

My application.rhtml page now has ’ \<%= debug(session) %\> ’ added to  
the page to view the session on the web page

I’ve added  
‘‘config.action\_controller.session\_store= :active\_record\_store’’ to  
the environment.rb page.

After a quick google earlier, I kept getting an invalid token error,  
so i read that adding ''protect\_from\_forgery :only =\>  
[:create, :update, :destroy] ‘’ to the user controller page resolves  
it. Which it did. I no longer get that error.

However - I have added the code as the book suggests. The user is  
still successfully added to the site, and visible in the database, but  
the flash message does not get displayed.

(if i delete this code, I can see the flash message again)

Any ideas??

Many Thanks!

---

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [September 8, 2009, 5:20pm UTC](https://www.ruby-forum.com/t/please-help-session-problem/175098/2 "2009-09-08T17:20:21Z")

</div>

I handle my flash notices in my layout file.

\<% if flash[:notice] -%\>

\<%= flash[:notice] %\>
\<% end -%\>

… which shows the flash notice in a particular location of my layout,  
which applies to all pages on my site. Otherwise, you will have to  
include which pages your flash notices appear on. Your flash notice  
could be appearing on the page but then you are redirecting to another  
page that might not have flash notices showing up on that page.

Using the above in your layout will make it so that your notices show up  
in all pages that use the layout.

---

<div class="post-metadata">

**Author:** ![RubyonRails\_newbie](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/r/9d8465/32.png) [@RubyonRails\_newbie](https://www.ruby-forum.com/u/RubyonRails_newbie)\
**Post date:** [September 8, 2009, 6:00pm UTC](https://www.ruby-forum.com/t/please-help-session-problem/175098/3 "2009-09-08T18:00:30Z")

</div>

I think Alpha B.'s already pointed out the problem, but I’d  
reiterate again that trying to follow RailsSpace on a modern Rails  
stack is not a good idea - too much has changed. Try to at least find  
a book written for Rails 2…

–Matt J.

On Sep 7, 5:40 pm, RubyonRails\_newbie [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
