Suppose this is my users controller:-
class UsersController < ApplicationController
def show
@user = session[:user]
end
def prepare
session[:user]= User.find(:first)
redirect_to :action => 'show'
end
def update
@user = session[:user]
@user.name = 'rai'
redirect_to :action => 'show'
end
end
View for show.html.erb
<%= @user.name %>
Show page
<%= link_to 'Update', :action=> 'update' %>
Now Explaining the issue:--- Suppose first time user opens the browser with
http://localhost:3000/users/prepare
o/p will be:---
Mohit Show page Update // supposing user table has values mohit as name
Now when he click on update he will get as output like this:--
rai Show page Update
But this should not happen cause
firstly when are at prepare action where value is fecthced from db and its mohit. and then he is redirected to show ie displying the values from session. ie mohit
Now when user click on the update he is redirected to update when value from session is stored to a user instance and the name attribute of that user instance has been modified to rai. and finally redirected to show page.
Now in this page when user's name is displayed its showing rai.. thats the QUESTION why?? cause session should store the same mohit value cause we havnt made any change in session..