Login/Logff Button -- doesn't update

update the partial in your controller method which destroys the session:

def logout
  session = nil

  render :update do |page|
    page.replace_html 'my_div', :partial => 'topnav'
  end
end

Mike

Mike Garey wrote:

update the partial in your controller method which destroys the session:

def logout
  session = nil

  render :update do |page|
    page.replace_html 'my_div', :partial => 'topnav'
  end
end

Mike

Mike,

excellent, thanks for the help. i have to review the page object.

best,

tim

I am almost there, the problem is that topnav is a partial included in
views\layouts\application.html.erb (i.e. layouts\_topnav). I have tried
all sorts of ways to get the partial to look at layouts\_topnav.html.erb
(things like :partial => '\layouts\_topnav'). this might be working, but
then i get a 'you have rendered twice' error.

any help greatly appreciated.

best,

tim

Mike Garey wrote:

this is almost working:

  def logout
    session[:user_id] = nil
    render :update do |page|
      page.replace_html 'header', :partial => '/layouts/nav'
    end
    flash[:notice] = "Logged out"
    redirect_to(:action => "login")
  end

but i get an error:

ActionController::DoubleRenderError in LoginController#logout

Can only render or redirect once per action

any thoughts on why this is?

best

tim

Tim Booher wrote:

Well it's exactly what it says, you can't render something and
redirect in the same action. Or to put things another way, if you
redirect (ie send back a 302 response) the browser is just going to
follow it, it doesn't make sense to also render: the body of the http
response is ignored. Even if you could it wouldn't make any
difference: you're generating some javascript to change the page, but
that page is being thrown away since the browser is being redirected
to a new location.

You shouldn't need to be doing anything much beyond what you put in
your first post, there's probably something silly tripping you up.
Messing around with ajax is almost certainly not what you need to do.

Fred

Fred,

Great point and it's well understood. My problem was that I was not
adequately destroying the session, nor testing for the session's
existence correctly. I built the helper method logged_in? which works
fine inside the partial.

best,

tim

also, you should probably place your topnav partial into views/shared.
That's where views that are to be shared between different actions
should be stored. Topnav isn't a layout, so it doesn't really belong
in the views/layouts dir.

Mike

How are you resetting your session? For example,
session = nil
as seen above doesn't do much (it just creates a local variable called
session and sets it to nil). If you want to clear out the whole
session use reset_session. Just session[:foo]=nil will also work if
you just want to clear that bit of it.

Fred

Fred,

great point. i am now using reset_session.

regards,

tim

Frederick Cheung wrote: