SitePoint Sponsor

User Tag List

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

    Simply Rails 2 ch 6 error pg 168-178

    I am receiving the following error. Thanks


    SyntaxError in StoriesController#index

    /Users/usdr/shovell/app/controllers/stories_controller.rb:16: syntax error, unexpected $end, expecting kEND

    _______________________________________________________________

    Copy of stories.controller.rb

    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])
    if @story.save
    flash[:notice] = 'Story submission succeeded'
    redirect_to stories_path
    else
    render :action => 'new'
    end
    end

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,176
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    Hi afowler1, welcome to the forums,
    If you indent you can see code blocks easier. i.e.
    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])
        if @story.save
          flash[:notice] = 'Story submission succeeded'
          redirect_to stories_path
        else
          render :action => 'new' 
        end 
      end
    As you can see, you're missing the "end" to close the class definition. The error message is bit confusing, because you may think there is a unexpected "end", when it really indicates that the script "ended" unexpectedly.

  3. #3
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you........ I am still getting the same error, should I check anything else? Also, when I use TextMate my code is indented but for some reason when I copy and paste it overrides the indent. Thank you again for your time.

    class StoriesController < ApplicationController
    def index
    @story = Story.findfirst, rder => 'RANDOM()')
    end

    def new
    @story = Story.new
    end

    def create
    @story = Story.new(params[:story])
    if @story.save
    flash[:notice] = 'Story submission succeeded'
    redirect_to stories_path
    else
    render :action => 'new'
    end
    end

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,176
    Mentioned
    191 Post(s)
    Tagged
    2 Thread(s)
    If you choose "Syntax -> Ruby" from the drop-down select above the post reply box, the indentation will be preserved and there won't be any smilies

    Code Ruby:
    .....
      def create
        @story = Story.new(params[:story])
        if @story.save
          flash[:notice] = 'Story submission succeeded'
          redirect_to stories_path
        else
          render :action => 'new'
        end
      end
    The "def" needs an "end" to close it, and the "if/else" needs an "end" to close it. But you're still missing the "end" that the class
    Code Ruby:
    class StoriesController < ApplicationController
    .....
    end
    needs.

  5. #5
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great! Thanks for your help. That of course fixed the problem. Have a great day!


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
  •