SitePoint Sponsor

User Tag List

Results 1 to 17 of 17

Threaded View

  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    5
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Lenz book - Chapter 7 - Page 199... HELP.

    I am getting an error... I am using Ruby 1.8.4, Rails 2.1.0.

    -----
    Code:
    NoMethodError in Story#show
    
    Showing story/show.rhtml where line #1 raised:
    
    You have a nil object when you didn't expect it!
    The error occurred while evaluating nil.name
    
    Extracted source (around line #1):
    
    1: <h2><&#37;= @story.name %></h2>
    2: <p><%= link_to @story.link, @story.link %></p>
    -----

    I have ensured that the permalinks exist... It's driving me NUTS.

    Code below...

    Story_controller.rb

    Code:
    Code Ruby:
    class StoryController < ApplicationController
      skip_before_filter :verify_authenticity_token
     
      def show
        @story = Story.find_by_permalink(params[:permalink])
      end 
      def index
        @story = Story.find(:first, :order => 'RAND()')
      end
      def new
        @story = Story.new(params[:story])
        if request.post? and @story.save
          flash[:notice] = 'Story submitted!'
          redirect_to :action => 'index'
        end
      end
    end
    I have checked this over and over... If someone could help, please do.

    EDIT:

    Okay, I even resorted to copying and pasting from the code archive. I AM FULL OF FAIL. Bleh. It didn't work. Perhaps the problem is with Rails 2.1.0. ???

    EDIT 2:

    What... The... F --

    It works now... ? I just had to restart WEBrick.

    ...

    Whatever, eh? Mods, delete this thread whenever... Sorry.
    Last edited by grenadier42; Jul 3, 2008 at 23:23.


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
  •