导轨路由错误

问题描述:

奇怪的错误。我是rails的新手。从一个新的安装导轨我连接到Oracle数据库,然后跑:导轨路由错误

jruby script/generate scaffold job oid:integer userid:integer name:string status:integer 

没有做别的事情,我开始了服务器,并进入了一个新的工作,然后我得到这个错误:

Routing Error 

job_url failed to generate from {:controller=>"jobs", :action=>"show", :id=>#<Job id: #<BigDecimal:d55a0f,'10000.0',1(8)>, oid: #<BigDecimal:10bb83e,'1324.0',4(8)>, userid: #<BigDecimal:6d234c,'1234.0',4(8)>, name: "asdfadsf", status: #<BigDecimal:1286c71,'1234.0',4(8)>, created_at: "2009-12-15 00:49:37", updated_at: "2009-12-15 00:49:37">}, expected: {:controller=>"jobs", :action=>"show"}, diff: {:id=>#<Job id: #<BigDecimal:853e51,'10000.0',1(8)>, oid: #<BigDecimal:1be4050,'1324.0',4(8)>, userid: #<BigDecimal:adb165,'1234.0',4(8)>, name: "asdfadsf", status: #<BigDecimal:15978e7,'1234.0',4(8)>, created_at: "2009-12-15 00:49:37", updated_at: "2009-12-15 00:49:37">} 

即使它抛出错误,它仍然创建记录。当我尝试查看记录时,我得到以下堆栈,这实际上是相同的错误。

ActionController::RoutingError in Jobs#show 

Showing app/views/jobs/show.html.erb where line #22 raised: 

edit_job_url failed to generate from {:controller=>"jobs", :action=>"edit", :id=>#<Job id: #<BigDecimal:18caa36,'10000.0',1(8)>, oid: #<BigDecimal:1fac733,'1324.0',4(8)>, userid: #<BigDecimal:12c1472,'1234.0',4(8)>, name: "asdfadsf", status: #<BigDecimal:f25f89,'1234.0',4(8)>, created_at: "2009-12-15 00:49:37", updated_at: "2009-12-15 00:49:37">}, expected: {:controller=>"jobs", :action=>"edit"}, diff: {:id=>#<Job id: #<BigDecimal:1b9cdfc,'10000.0',1(8)>, oid: #<BigDecimal:1829097,'1324.0',4(8)>, userid: #<BigDecimal:e2d663,'1234.0',4(8)>, name: "asdfadsf", status: #<BigDecimal:691ccf,'1234.0',4(8)>, created_at: "2009-12-15 00:49:37", updated_at: "2009-12-15 00:49:37">} 
Extracted source (around line #22): 

19: </p> 
20: 
21: 
22: <%= link_to 'Edit', edit_job_path(@job) %> | 
23: <%= link_to 'Back', jobs_path %> 
RAILS_ROOT: /opt/code/import 

Application Trace | Framework Trace | Full Trace 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:426:in `raise_named_route_error' 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/routing/route_set.rb:387:in `generate' 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/url_rewriter.rb:205:in `rewrite_path' 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/url_rewriter.rb:184:in `rewrite_url' 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/url_rewriter.rb:162:in `rewrite' 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_controller/base.rb:634:in `url_for' 
/opt/jruby/lib/ruby/gems/1.8/gems/actionpack-2.3.5/lib/action_view/helpers/url_helper.rb:85:in `url_for' 
(eval):16:in `edit_job_path' 
/opt/code/import/app/views/jobs/show.html.erb:22:in `_run_erb_app47views47jobs47show46html46erb' 
/opt/code/import/app/controllers/jobs_controller.rb:18:in `show' 
Request 

Parameters: 

{"id"=>"10000"} 
Show session dump 

Response 

Headers: 

{"Cache-Control"=>"no-cache", 
"Content-Type"=>"text/html"} 

当我删除了“edit_job_path”方法错误消失,所以我知道它只是有一个问题渲染路线,但我不知道为什么,因为它似乎有正确的信息。我的意思是这是一个样板脚手架,所以....在此先感谢您的帮助!

这是因为您的ID字段是BigDecimal,它应该是Integer。它将一个数字如“1234.54”分成两部分,如{:action => "1234", :format => "54" }

+0

宾果。谢谢瑞恩!我意识到在发布BigDecimal后发生了一些事情,但并不确定是什么。你钉了它。这是因为我使用的是JRuby,我不需要这么做,因此我将切换回非Java Java虚拟机。 – 2009-12-16 16:23:07

请确保您有这条线在你的config/routes.rb文件:

map.resources :jobs 

,也需要运行“耙路”,看看哪条路线可供选择。 * path和* url方法由您在routes.rb文件中定义的命名路由和资源生成。更多信息here