SitePoint Sponsor

User Tag List

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

    Angry Suspecting Errors in Simply Rails 2

    Hi All
    I am new to Rails but not new to programming.
    I have been trying to learn Rails using the Simply Rails 2 Book that I purchased and downloaded.
    I have spent hours repeating the steps in the first 6 chapters, at the point of all most giving up I managed to finally get through it. I don't want anybody else to go through the same pain that I did to get this working.

    PLEASE NOTE: If the following errors are in fact not errors and I have failed in following the instructions, please let me know.

    My suspected errors are as follows


    On page 159 the line
    <% form_for @story do |f| %>
    did not work for me
    I got it working using
    <% form_for :story do |f| %>
    NOTE: I have replaced the @ symbol with a :


    On page 164 I was asked to add
    map.resources :stories
    to my routes.rb file
    I found that it made no difference if I added that or not (test done after I got everything working)

    On page 166 I found that the following did not work for me

    def create
    @story = Story.new(params[:story])
    @story.save
    end

    I had to add the code

    @story = Story.new(params[:story])
    @story.save

    to the already existing "new" method (not create another method called "create")

    If I am wrong I would like to know where I went wrong. If I am correct I hope I have helped other get over this hurdle.

    Cheers
    mistermac

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

    It case you don't know about these, this book has an errata page http://www.sitepoint.com/books/rails2/errata.php and you can get example files from the code archive http://www.sitepoint.com/books/rails2/code.php

    I'm still very little more than a RoR newbie myself, but I have succesfully worked my way through this book (and a few other tutorials).

    The code I have for the new.html.erb file for that chapter is
    Code Ruby:
    <%= error_messages_for 'story' %>
    <% form_for @story do |f| %>
      <p>
        name:<br />
        <%= f.text_field :name %>
      </p>
      <p>
        link:<br />
        <%= f.text_field :link %>
      </p>
      <p>
        <%= submit_tag %>
      </p>
    <% end %>
    and it worked fine for me. AFAIK the "@" symbol is used for "instance variables" and (in this use) the ":" colon symbol indicates a "symbol" of the class.

    As for the routes.rb edit having no effect,
    # The priority is based upon order of creation: first created -> highest priority.
    so it may have something to do with where you put the line. I put mine as the first one here
    Code Ruby:
      # Sample resource route (maps HTTP verbs to controller actions automatically):
      #   map.resources :products
      map.resources :stories
    but as you are also having trouble with @stories in the erb file it may be something else that's the problem.

    My stories_controller.rb file for that chapter looks like
    Code Ruby:
    class StoriesController < ApplicationController
      def index
         @story = Story.find(:first, :order => 'RANDOM()')
      end
      def new
        @story = Story.new
      end
      def create
        @story = Story.new(params[:story])
    #    @story.save
        if @story.save
          flash[:notice] = 'Story submission succeeded'
          redirect_to stories_path
        else
          render :action => 'new'
        end      
      end
    end
    and it too worked fine for me.

    It took me 3-4 attempts too get through the book sucessfully, needing to go back to square 1 twice. It was frustrating for me as I was excited about learning something new, but I hopefully learned from my mistakes. My mistakes usually were a result of both my being a "newbie" and my desire to make quick progress causing me to overlook something in the instructions.

    The first thing I suggest you do is compare your files with those in the code archive. You may discover a difference somewhere in them.

    If you do go back to the beginning (well, back to after the install process) I suggest you do what I did. After making it through each chapter sucessfully, I saved a copy of the shovell folder. eg. shovell_4, so that I could go back to it if/when I ran into a problem in the next chapter.

  3. #3
    SitePoint Member
    Join Date
    Feb 2009
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Thumbs up

    Hi Mittineague
    Thanks for your help, sounds like you are getting quite good at RoR. I can't wait to learn more. I really like this language, I use Python a fair bit and this is kinda similar in some syntax.
    I did not know of the Errata page so that will really come in handy.
    Thanks again


Tags for this Thread

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
  •