1

尝试访问 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
4

1 回答 1

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最后一行有一个额外的内容。

于 2013-01-26T19:08:16.817 回答