* Please Help - Session problem *

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”

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!

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.

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 [email protected]