这本书的章节 8.1 task C1,这章节的任务是创建针对付费用户的接口
1.生成控制器 store,并且指定 action 为 index 命令如下,rails generate controller store index 这时如果访问 localhost:3000/store/index 页面展示的信息如下
Store#index Find me in app/views/store/index.html.erb
Depot::Application.routes.draw do
get "store/index"
resources :products
# ...
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
# root :to => "welcome#index"
root :to => 'store#index', :as => 'store'
# ...
end
这里面的:as=>'store'我并不清楚这个参数代表啥意思? 3.删除 public 目录中的 index.html 文件,我已经删除了 .
现在的问题是启动 server 就报错,如下信息。日志我也看的不懂,但感觉主要是 undefined local variable or method `store' ,但是 store 这个变量我需要额外定义吗?
logs:
=> Booting WEBrick
=> Rails 3.2.2 application starting in development on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
Exiting
/home/Crabby/depot/config/routes.rb:56:in `block in <top (required)>': undefined local variable or method `store' for #<ActionDispatch::Routing::Mapper:0x00000002a31068> (NameError)
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:276:in `instance_exec'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:276:in `eval_block'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/actionpack-3.2.2/lib/action_dispatch/routing/route_set.rb:254:in `draw'
from /home/Crabby/depot/config/routes.rb:1:in `<top (required)>'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `block in load'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:236:in `load_dependency'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/dependencies.rb:245:in `load'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in `block in load_paths'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in `each'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:40:in `load_paths'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:16:in `reload!'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:26:in `block in updater'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/file_update_checker.rb:78:in `call'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/activesupport-3.2.2/lib/active_support/file_update_checker.rb:78:in `execute'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:27:in `updater'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/routes_reloader.rb:7:in `execute_if_updated'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application/finisher.rb:66:in `block in <module:Finisher>'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `instance_exec'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/initializable.rb:30:in `run'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `each'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/initializable.rb:54:in `run_initializers'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/application.rb:136:in `initialize!'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/Crabby/depot/config/environment.rb:5:in `<top (required)>'
from /home/Crabby/depot/config.ru:4:in `require'
from /home/Crabby/depot/config.ru:4:in `block in <main>'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:51:in `instance_eval'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:51:in `initialize'
from /home/Crabby/depot/config.ru:1:in `new'
from /home/Crabby/depot/config.ru:1:in `<main>'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:40:in `eval'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/builder.rb:40:in `parse_file'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:200:in `app'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands/server.rb:46:in `app'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:301:in `wrapped_app'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/rack-1.4.1/lib/rack/server.rb:252:in `start'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands/server.rb:70:in `start'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands.rb:55:in `block in <top (required)>'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands.rb:50:in `tap'
from /home/Crabby/.rvm/gems/ruby-1.9.3-p125/gems/railties-3.2.2/lib/rails/commands.rb:50:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'