2

我是 Rails 新手,我遵循了“head first with rails”这本书

这是我做的步骤:

$rails tickets

shaun@master ~/Desktop/tickets $ rails generate scaffold ticket name:string seat_id_seg:string address:text price_paid:decimal email_address:string


shaun@master ~/Desktop/tickets $ rake routes
    tickets GET    /tickets(.:format)          tickets#index
            POST   /tickets(.:format)          tickets#create
 new_ticket GET    /tickets/new(.:format)      tickets#new
edit_ticket GET    /tickets/:id/edit(.:format) tickets#edit
     ticket GET    /tickets/:id(.:format)      tickets#show
            PUT    /tickets/:id(.:format)      tickets#update
            DELETE /tickets/:id(.:format)      tickets#destroy


    shaun@master ~/Desktop/tickets $ rake db:migrate
==  CreateTickets: migrating ==================================================
-- create_table(:tickets)
   -> 0.1065s
==  CreateTickets: migrated (0.1069s) =========================================


when i try going to localhost:3000/tickets

it comes out Routing Error and says "No route matches [GET] "/tickets"

> Started GET "/tickets" for 192.168.1.8 at Thu Jul 12 08:45:38 +0800 2012
Connecting to database specified by database.yml

ActionController::RoutingError (No route matches [GET] "/tickets"):
  actionpack (3.2.6) lib/action_dispatch/middleware/debug_exceptions.rb:21:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/show_exceptions.rb:56:in `call'
  railties (3.2.6) lib/rails/rack/logger.rb:26:in `call_app'
  railties (3.2.6) lib/rails/rack/logger.rb:16:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/request_id.rb:22:in `call'
  rack (1.4.1) lib/rack/methodoverride.rb:21:in `call'
  rack (1.4.1) lib/rack/runtime.rb:17:in `call'
  activesupport (3.2.6) lib/active_support/cache/strategy/local_cache.rb:72:in `call'
  rack (1.4.1) lib/rack/lock.rb:15:in `call'
  actionpack (3.2.6) lib/action_dispatch/middleware/static.rb:62:in `call'
  railties (3.2.6) lib/rails/engine.rb:479:in `call'
  railties (3.2.6) lib/rails/application.rb:220:in `call'
  rack (1.4.1) lib/rack/content_length.rb:14:in `call'
  railties (3.2.6) lib/rails/rack/log_tailer.rb:17:in `call'
  rack (1.4.1) lib/rack/handler/webrick.rb:59:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service'
  /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run'
  /usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread'
  /usr/lib/ruby/1.8/webrick/server.rb:95:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `each'
  /usr/lib/ruby/1.8/webrick/server.rb:92:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:23:in `start'
  /usr/lib/ruby/1.8/webrick/server.rb:82:in `start'
  rack (1.4.1) lib/rack/handler/webrick.rb:13:in `run'
  rack (1.4.1) lib/rack/server.rb:265:in `start'
  railties (3.2.6) lib/rails/commands/server.rb:70:in `start'
  railties (3.2.6) lib/rails/commands.rb:55
  railties (3.2.6) lib/rails/commands.rb:50:in `tap'
  railties (3.2.6) lib/rails/commands.rb:50
  script/rails:6:in `require'
  script/rails:6


  Rendered /var/lib/gems/1.8/gems/actionpack-3.2.6/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (2.8ms)

我该如何解决这个问题?我希望能够看到主页以及所有指向索引、创建新票证、编辑、显示、更新和删除的链接。

4

1 回答 1

2

我刚刚完全按照您为新的 Rails 3.2.6 应用程序编写的操作,它对我来说效果很好。您错过的唯一步骤是rake db:migrate在脚手架生成之后运行。试试看它是否有效。

于 2012-07-12T00:25:16.083 回答