无法访问家庭路线?

时间:2013-01-26 18:49:54

标签: ruby-on-rails ruby syntax

尝试访问localhost:3000 / static_pages / home时出现以下错误:

SyntaxError in StaticPagesController#home

/Users/user/Sites/rails_projects/sample_app/app/helpers/application_helper.rb:9: syntax error, unexpected keyword_end, expecting $end
Rails.root: /Users/user/Sites/rails_projects/sample_app

Application Trace | Framework Trace | Full Trace
app/controllers/application_controller.rb:1:in `<top (required)>'
app/controllers/static_pages_controller.rb:1:in `<top (required)>' 

routes.rb内容:

SampleApp::Application.routes.draw do

  get "static_pages/home"

  get "static_pages/help"

  get "static_pages/about"

  get "static_pages/contact"

end

application_helper.rb内容:

def full_title(page_title)
base_title = "Ruby on Rails Tutorial Sample App"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
end

static_pages_controller.rb内容:

class StaticPagesController < ApplicationController
  def home
  end

  def help
  end

  def about
  end

  def contact
  end
end

1 个答案:

答案 0 :(得分:0)

application_helper.rb似乎被打破了。你可能想要这样的东西:

module ApplicationHelper

  def full_title(page_title)
    base_title = "Ruby on Rails Tutorial Sample App"
    if page_title.empty?
      base_title
    else
      "#{base_title} | #{page_title}"
    end
  end

end

似乎module行丢失了。这就是为什么Ruby在最后一行抱怨额外的end