SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    ruby error in book

    Hi,
    I am trying to learn RoR from the book 'Build your own Ruby on Rails Web Applications'.

    Everything is going fine. However I am stuck on this code

    Please view the attached jpg code as this forum is not allowing me to post signs!(code.jpg)

    (page 214 of the book)

    If the above is present in the story_controller.rb file, then browsers with javascript ENABLED do not update the score or the vote history box.

    If I hash out the above entries, everything works fine. Any suggestions?

    Thanks
    Attached Images Attached Images

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,140
    Mentioned
    190 Post(s)
    Tagged
    2 Thread(s)
    HI innocuous, welcome to the forums,

    I have the book "Simply Rails 2" but not "Build your own" except for the sample chapters which don't go up to page 214. At the risk of confusing things, SR2 has
    Ensuring Graceful Degradation
    To implement a fallback action for browsers that don’t support Ajax, we actually just need to take care of the different treatment for browsers with and without Javascript support on the behalf of the create action of VotesController, since the HTML generated by the form_remote_tag helper we’ve used to generate our voting form is already fully compatible with both worlds.
    Our plan is to redirect users back to the story page after we’ve processed their votes with their non-Javascript browsers while users with Ajax-enabled browsers can watch as the total number of votes is updated and highlighted without a page reload. To instruct our votes controller to take appropriate action, whether it’s dealing with
    an Ajax request or a regular HTTP POSTrequest, we need to modify the createaction in our VotesController class like so:
    14-votes_controller.rb (excerpt)
    Code Ruby:
    class VotesController < ActionController::Base
      def create
        @story = Story.find(params[:story_id])
        @story.votes.create
     
        respond_to do |format|
          format.html { redirect_to @story }
          format.js
        end
      end
    Which looks somewhat similar to your
    Code Ruby:
      def Vote
        @story = Story.find(params[:id])
        @story.votes.create
     
        respond_to do |wants|
        wants.html { redirect_to :action => 'show'
                                          :permalink => @story.permalink }
        wants.js     { render }
      end
    end
    Sorry but I don't really know what the problem is for you, I'm hoping the above might help anyway.

    My thinking is that maybe you are working through an older book but not with the same app versions that were in use when the book was written?

    I didn't see anything listed in the "errata" http://www.sitepoint.com/books/rails1/errata.php
    But you could compare your files to those in the code archive http://www.sitepoint.com/books/rails1/code.php

  3. #3
    SitePoint Member
    Join Date
    Apr 2009
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Seems the same...I'll try it out and see. I guess I need to buy the updated book! The 1st edition tells me to modify the story_controller and here its telling me to modify the vote_controller!

    Thanks


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
  •