SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Member schlick's Avatar
    Join Date
    May 2007
    Location
    Canberra
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    RoR Book and Sessions

    Hi,

    I'm working my way through the SitePoint RoR Web Apps book and like others I have encountered various typos/errors along the way, some listed on the errata site and others not (which I'll send through separately). Despite the errors I'm enjoying the book and it is really helping me to get a handle of Rails. I do wonder though whether more time could've been spent on proofing the code before it was realised. Also will I be able to download an update to my purchased pdf so that I have a copy that is updated with all the corrections.

    Anyway, my problem that I'm experiencing is with sessions. I can't seem to get the Shovell application to work correctly with sessions. I've even downloaded the completed application from the code archive and that doesn't work either.

    What's happening is that the app only redirects to the frontpage irrespective of where the user was at. The book says that the user will be returned to the original page they were at when they clicked on the login link. It apparently does this by storing a :return_to value in the session. From what I can tell the :return_to value is not being stored or is blank.

    Any advice on what's causing this would be most appreciated!

  2. #2
    SitePoint Member schlick's Avatar
    Join Date
    May 2007
    Location
    Canberra
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Sessions problem sorted out

    Okay, I'll answer my own question regarding the session problem...

    It isn't an error in the application or a typo in the book. It is purely a case of having a different perspective on the requirements.

    In the book, initially only the "add new story" function is restricted to logged in users. As part of this the requirement is that users are redirected back to the add new story page after logging in. This is where the session[:return_to] comes in.

    Later on, in the next chapter, the voting is restricted and users must login before being able to vote. The vote action was added to the before_filter in the Story controller. This would stop users being able to directly address the vote url and make a vote without logging in. Great.

    Now, this is where I went awry. I then thought that the redirection requirement from the new action was meant to be applied to all instances of logging in. In other words, I expected users to be redirected to whatever page they were on when they clicked on a "login" link eg on the upcoming stories page and on an individual story page. But this is not the case.

    To make this work would require rethinking/reworking the application. I had a go but got stuck when I realised that you don't to redirect users back to a logout page! They'd log in and automatically be logged out again. But that was with me updating the session[:return_to] page every time (and on every page) the login link was displayed as part of the global navigation. Also, it would break on the login page itself because you'd get redirected back to the login page.

    I reckon one solution would be to get the "previous" page in the login action and assign that to session[:return_to] but I don't know how to get that information. Alternatively, if I could pass a parameter to the login action, I could pass in the current page with request.request_uri but I don't exactly know how to do that either yet. And I'd still have the issue with the logout and login pages where I wouldn't want to pass in any default parameter.

    Anyway, once I figured out that the application wasn't designed to work the way I thought the problem disappeared. I could spend time trying to make my idea work but I think I'll move onto the next chapter!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •