2014-02-26 26 views
0

1.我使用ruby-2.0.0 rails-4.0
2.我按照教程http://ruby.railstutorial.org/chapters/static-pages#top
3.我運行了「bundle install」命令。
4.Here是輸出「包安裝」命令如何生成Staticpages控制器?

[email protected]:~/rais_project/sample_app$ bundle install 
Using rake (10.1.1) 
Using i18n (0.6.9) 
Using minitest (4.7.5) 
Using multi_json (1.8.4) 
Using atomic (1.1.14) 
Using thread_safe (0.1.3) 
Using tzinfo (0.3.38) 
Using activesupport (4.0.3) 
Using builder (3.1.4) 
Using erubis (2.7.0) 
Using rack (1.5.2) 
Using rack-test (0.6.2) 
Using actionpack (4.0.3) 
Using mime-types (1.25.1) 
Using polyglot (0.3.4) 
Using treetop (1.4.15) 
Using mail (2.5.4) 
Using actionmailer (4.0.3) 
Using activemodel (4.0.3) 
Using activerecord-deprecated_finders (1.0.3) 
Using arel (4.0.2) 
Using activerecord (4.0.3) 
Using mini_portile (0.5.2) 
Using nokogiri (1.6.1) 
Using xpath (2.0.0) 
Using capybara (2.1.0) 
Using ffi (1.9.3) 
Using childprocess (0.5.1) 
Using coffee-script-source (1.7.0) 
Using execjs (2.0.2) 
Using coffee-script (2.2.0) 
Using thor (0.18.1) 
Using railties (4.0.3) 
Using coffee-rails (4.0.1) 
Using diff-lcs (1.2.5) 
Using hike (1.2.3) 
Using jbuilder (1.0.2) 
Using jquery-rails (3.0.4) 
Using json (1.8.1) 
Using bundler (1.5.2) 
Using tilt (1.4.1) 
Using sprockets (2.11.0) 
Using sprockets-rails (2.0.1) 
Using rails (4.0.3) 
Using rdoc (3.12.2) 
Using rspec-core (2.13.1) 
Using rspec-expectations (2.13.0) 
Using rspec-mocks (2.13.1) 
Using rspec-rails (2.13.1) 
Using rubyzip (0.9.9) 
Using sass (3.2.14) 
Using sass-rails (4.0.1) 
Using sdoc (0.3.20) 
Using websocket (1.0.7) 
Using selenium-webdriver (2.35.1) 
Using sqlite3 (1.3.8) 
Using turbolinks (1.1.1) 
Using uglifier (2.1.1) 
Your bundle is complete! 
Gems in the group production were not installed. 
Use `bundle show [gemname]` to see where a bundled gem is installed. 

5.Next我跑這個命令
「$軌生成器StaticPages家庭幫助--no測試框架」。

輸出一定是如圖所示根據教程

create app/controllers/static_pages_controller.rb 
    route get "static_pages/help" 
    route get "static_pages/home" 
    invoke erb 
    create app/views/static_pages 
    create app/views/static_pages/home.html.erb 
    create app/views/static_pages/help.html.erb 
    invoke helper 
    create app/helpers/static_pages_helper.rb 
    invoke assets 
    invoke coffee 
    create  app/assets/javascripts/static_pages.js.coffee 
    invoke scss 
    create  app/assets/stylesheets/static_pages.css.scss 

之下,但我得到的輸出

/home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:7:in `<module:Handlers>': uninitialized constant Erubis (NameError) 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:6:in `<class:Template>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:5:in `<module:ActionView>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:4:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers.rb:10:in `extended' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:97:in `extend' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:97:in `<class:Template>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:7:in `<module:ActionView>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:5:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder_template.rb:56:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder.rb:340:in `require' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder.rb:340:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler.rb:131:in `require' 
    from /home/user/rais_project/sample_app/config/application.rb:12:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.3/lib/rails/commands.rb:43:in `require' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.3/lib/rails/commands.rb:43:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

6.我試圖與本教程中的下一個命令「$軌生成控制器static_pages ...「,爲此必須生成一個名爲」static_pages_controller.rb「的控制器。
的輸出「$軌生成器static_pages ......」是

/home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:7:in `<module:Handlers>': uninitialized constant Erubis (NameError) 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:6:in `<class:Template>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:5:in `<module:ActionView>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:4:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers.rb:10:in `extended' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:97:in `extend' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:97:in `<class:Template>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:7:in `<module:ActionView>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:5:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder_template.rb:56:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder.rb:340:in `require' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder.rb:340:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler.rb:131:in `require' 
    from /home/user/rais_project/sample_app/config/application.rb:12:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.3/lib/rails/commands.rb:43:in `require' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.3/lib/rails/commands.rb:43:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 
[email protected]:~/rais_project/sample_app$ clear 

[email protected]:~/rais_project/sample_app$ $ rails generate controller static_pages ... 
$: command not found 
[email protected]:~/rais_project/sample_app$ rails generate controller static_pages ... 
/home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:7:in `<module:Handlers>': uninitialized constant Erubis (NameError) 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:6:in `<class:Template>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:5:in `<module:ActionView>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers/erb.rb:4:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template/handlers.rb:10:in `extended' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:97:in `extend' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:97:in `<class:Template>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:7:in `<module:ActionView>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/actionpack-4.0.3/lib/action_view/template.rb:5:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder_template.rb:56:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder.rb:340:in `require' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/jbuilder-1.0.2/lib/jbuilder.rb:340:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:76:in `block (2 levels) in require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `each' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:72:in `block in require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `each' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler/runtime.rb:61:in `require' 
    from /home/user/.rvm/gems/[email protected]/gems/bundler-1.5.2/lib/bundler.rb:131:in `require' 
    from /home/user/rais_project/sample_app/config/application.rb:12:in `<top (required)>' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.3/lib/rails/commands.rb:43:in `require' 
    from /home/user/.rvm/gems/[email protected]_rails_4_0/gems/railties-4.0.3/lib/rails/commands.rb:43:in `<top (required)>' 
    from bin/rails:4:in `require' 
    from bin/rails:4:in `<main>' 

但這種控制器不generated.Can請你幫忙嗎?

的Gemfile

source 'https://rubygems.org' 
ruby '2.0.0' 
#ruby-gemset=railstutorial_rails_4_0 

gem 'rails', '4.0.3' 

group :development, :test do 
    gem 'sqlite3', '1.3.8' 
    gem 'rspec-rails', '2.13.1' 
end 

group :test do 
    gem 'selenium-webdriver', '2.35.1' 
    gem 'capybara', '2.1.0' 
end 

gem 'sass-rails', '4.0.1' 
gem 'uglifier', '2.1.1' 
gem 'coffee-rails', '4.0.1' 
gem 'jquery-rails', '3.0.4' 
gem 'turbolinks', '1.1.1' 
gem 'jbuilder', '1.0.2' 

group :doc do 
    gem 'sdoc', '0.3.20', require: false 
end 

group :production do 
    gem 'pg', '0.15.1' 
    gem 'rails_12factor', '0.0.2' 
end 
+1

'bundle exec rails生成控制器StaticPages home help --no-test-framework'? –

+0

我執行了這個命令,但沒有生成控制器 – user3355409

+0

你的錯誤實際上是在這裏給出的:'未初始化的常量Erubis(NameError)'。發佈您的Gemfile並可能編輯該問題以查看是否有人可以提供幫助。快速谷歌顯示它可能是與傾斜寶石。 – 2014-02-26 13:56:29

回答

0

好吧,我沒有信譽發表評論,但在我看來像你鍵入$這裏:

[email protected]:~/rais_project/sample_app$ $ rails generate controller static_pages ... 
$: command not found 

你可能會打字兩次。記住,在Linux上,你不需要每次都輸入它。雖然你第二次沒有。所以我不知道。

我只在一年前開始使用rails。我對你的建議是:

確保你運行的是簡單版本的Linux,例如Ubuntu或Mint。 使用RVM進行安裝。完全按照教程。熟悉殼牌的Terminal &。老實說,這看起來像某種配置錯誤。

我不認爲你的問題是用你用來生成你的控制器的命令,但在本教程中更遠的地方。

我會建議深吸一口氣,並減慢通過教程回溯你的步驟。我認爲這只是一個配置問題。 (只要我猜)。保持冷靜,並與鐵軌樂趣!