我有带有自定义主键的模型:
文档.rb
class Document < ActiveRecord::Base
set_primary_key "token"
end
路线.rb:
MyApp::Application.routes.draw do
resources :documents, :only => [:index, :show, :create]
end
当我创建新文档时,出现错误:
No route matches {:controller=>"documents", :id=>#<Document id: "b430cfe73aaa5235fbfe", token: "b430cfe73aaa...
当我切换到使用 :id 作为主键时,一切正常。但是我需要使用 token 。
我使用:rails 3.0.0 和 ruby 1.8.7(2010-04-19 补丁级别 253)[i686-linux],MBARI 0x8770,Ruby 企业版 2010.02
感谢您的帮助。
最佳答案
尝试添加到document.rb
def to_param
token
end
关于ruby - 使用自定义主 ID 在 rails3 中进行路由,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3768740/