Action Controller: Getting syntax error

Hi–

I’m working my way through the book, Build Your Own Ruby on Rails Web
Applications (Sitepoint). I have run into a problem in Chapter 6; I
can’t get the ActionController (story.controller.rb) to run correctly.

I keep on getting an error which reads:
SyntaxError in StoryController#new
app/controllers/story_controller.rb:13: parse error, unexpected $,
expecting kEND

Since I’m new to RoR, I can’t figure out the error message and correct
the problem. Can someone help me?

Here is the code in the story.controller.rb file:

class StoryController < ApplicationController
def index
@story = Story.find(:first, :order=>‘RAND()’)
end
def new
@story = Story.new(params[:story])
if request.post?
@story.save
redirect_to :action => ‘index’
end
end

Thanks in advance.

Paul D. wrote:

Hi–

I’m working my way through the book, Build Your Own Ruby on Rails Web
Applications (Sitepoint). I have run into a problem in Chapter 6; I
can’t get the ActionController (story.controller.rb) to run correctly.

I keep on getting an error which reads:
SyntaxError in StoryController#new
app/controllers/story_controller.rb:13: parse error, unexpected $,
expecting kEND

Since I’m new to RoR, I can’t figure out the error message and correct
the problem. Can someone help me?

Here is the code in the story.controller.rb file:

class StoryController < ApplicationController
def index
@story = Story.find(:first, :order=>‘RAND()’)
end
def new
@story = Story.new(params[:story])
if request.post?
@story.save
redirect_to :action => ‘index’
end
end

Thanks in advance.

You have an end missing

try this

class StoryController < ApplicationController
def index
@story = Story.find(:first, :order=>‘RAND()’)
end

def new
@story = Story.new(params[:story])
if request.post?
@story.save
redirect_to :action => ‘index’
end
end
end

if you indent your code you may spot the error more easily

Thank you, your suggested change works.

I will remember to check my “end” syntax and to indent my code.

You have an end missing

try this

class StoryController < ApplicationController
def index
@story = Story.find(:first, :order=>‘RAND()’)
end

def new
@story = Story.new(params[:story])
if request.post?
@story.save
redirect_to :action => ‘index’
end
end
end

if you indent your code you may spot the error more easily

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs