SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    AJAX on faith in RoR

    This is probably trivial, however, it's bugging me, figuratively speaking. In the AJAX implementation in Chapter 7 of "Build Your Own Ruby on Rails Web Applications" how does vote.rjs know to apply it's effects to show.rhtml? It doesn't precisely follow the action - view paradigm. Is it as simple as 'because show.rhtml is the current/active/whatever page'?

    As an aside, I've spent a number of years in professional, enterprise level web application development primarily with ISS ASP/ADO and .NET technology. I must say, I have never found anything as refreshing as RoR.

    MrPete

  2. #2
    SitePoint Guru
    Join Date
    Aug 2005
    Posts
    986
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't own the book, can you give more information?

    Let's try anyway:

    vote.rjs is applied to the page loaded in your browser, this just happens to be show.rhtml. Rails doesn't re-parse show.rhtml: it creates Javascript code that changes the page in the browser.

    So:

    1) User visits show.rhtml
    2) User clicks a link or submits a form. This calls vote.rjs
    3) Vote.rjs generates Javascript code
    4) Your browser runs this code

    So Rails doesn't really need to know which page is loaded in the browser; it just generates Javascript code. You can view the code by visiting /yourcontroller/vote/[other params].

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks, Fenrir2, it was as simple as I had supposed.


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
  •