2014-04-04 53 views
0

我正在研究一个应用程序,我必须为路线放置一些自定义导轨参数,并且当我尝试访问与show关联的页面时,我一直收到no route found错误方法。该应用程序允许我访问我的edit页面,所以我知道它在某种程度上正在工作,但我必须发生错误,我没有看到与正常视图混淆的地方。自定义参数依赖于为每个对象自定义创建的:identifier。因为应用程序管理着几个机构,所有这些机构都有它们的对象和文件,所以我必须处理好几组不同的路径来处理每个不同的事情。机构的路线似乎工作正常,但第二组,:intellectual_objects是那些不工作。在自定义导轨参数中找不到路线错误

这是我的路线文件(不相关的部分除外):

Fluctus::Application.routes.draw do 

    get "institutions/:institution_identifier/objects", to: 'intellectual_objects#index', as: :institution_intellectual_objects, :constraints => { :institution_identifier => /[\w+\.]+/ } 
    post "institutions/:institution_identifier/objects", to: 'intellectual_objects#create', :constraints => { :institution_identifier => /[\w+\.]+/ } 

    #Intellectual Object Routes 
    #get "objects/:institution_identifier", to: 'intellectual_objects#index', as: :institution_intellectual_objects, :constraints => { :institution_identifier => /[\w+\.]+/ } 
    #post "objects/:institution_identifier", to: 'intellectual_objects#create', :constraints => { :institution_identifier => /[\w+\.]+/ } 

    patch "objects/:intellectual_object_identifier", to: 'intellectual_objects#update', :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 
    put "objects/:intellectual_object_identifier", to: 'intellectual_objects#update', :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 
    delete "objects/:intellectual_object_identifier", to: 'intellectual_objects#destroy', :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 
    get "objects/:intellectual_object_identifier/edit", to: 'intellectual_objects#edit', as: :edit_intellectual_object, :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 
    get "objects/:intellectual_object_identifier/events", to: 'events#index', as: :intellectual_object_events, :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 
    post "objects/:intellectual_object_identifier/events", to: 'events#create', :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 
    get "objects/:intellectual_object_identifier", to: 'intellectual_objects#show', as: :intellectual_object, :constraints => { :intellectual_object_identifier => /[\w+\/\.]+/ } 

    #post "objects/institution_identifier/:intellectual_object_identifier/data", to: 'generic_files#create', as: intellectual_object_generic_files, :constraints => { [:intellectual_object_identifier, :institution_identifier] => /[\w+\.]/ } 
    #patch "objects/institution_identifier/:intellectual_object_identifier/data/:filename", to: 'generic_files#update', :constraints => { [:intellectual_object_identifier, :institution_identifier] => /[\w+\.]/ } 

    Blacklight.add_routes(self) 

    mount Hydra::RoleManagement::Engine => '/' 

    root :to => "catalog#index" 
end 

这是我IntellectualObject控制器:

​​

我收到以下错误,当我尝试访问show路线(例如:localhost:3000/objects/test.org/126939282):

ActionController::UrlGenerationError in IntellectualObjects#show 
Showing /Users/kec6en/HydraApp/fluctus/app/views/intellectual_objects/_facet_limit.html.erb where line #11 raised: 

No route matches {:action=>"index", :intellectual_object_identifier=>"columbia.edu/798d6e812041532c", :controller=>"intellectual_objects", :f=>{"institution_name_ssi"=>["Columbia University"]}} 

的参数显示:

{"intellectual_object_identifier"=>"columbia.edu/798d6e812041532c"} 

当我运行在IntellectualObjectController

Failure/Error: get :show, intellectual_object_identifier: obj1 
ActionController::UrlGenerationError: 
    No route matches {:intellectual_object_identifier=>"kaulkedurgan.org13/39b1eb47-da8b-4145-b03b-5f1851407012", :controller=>"intellectual_objects", :action=>"show"} 

我只是不明白,因为路线是有我的规格测试,我发现了这个错误,有的他们似乎在应用程序中工作,但每个人都在我的规格测试中失败。任何和所有的帮助表示赞赏。谢谢。

+0

tl; dr - 对不起。你能否让这个问题更简洁? –

回答

1

您的路线intellectual_objects#index的约束条件是:institution_identifier应匹配/[\w+\.]+/,但columbia.edu/798d6e812041532c不匹配该正则表达式。即使您将\/添加到您的正则表达式中,我也确信斜杠会混淆Rails路由系统。

也许你想的路线更改为类似这样

get "institutions/:institution_identifier/:some_id/objects", 
    to: 'intellectual_objects#index', 
    as: :institution_intellectual_objects, 
    constraints: { institution_identifier: /[\w+\.]+/ } 

而不是提供columbia.edu(institution_identifier)和798d6e812041532c(SOME_ID)作为单独的值。

+0

我为你解决了问题 –

+0

'institution_identifier'没有这些约束,因为它只是'columbia.edu'部分。 'intellectual_object_identifier'是你上面确定的全部。 – user3254621

+0

而您的'intellectual_object_identifier' regexp'/ [\ w + \/\。。] + /'不匹配:'kaulkedurgan.org13/39b1eb47-da8b-4145-b03b-5f1851407012'。我建议重新考虑在URL的可变部分有'/'的想法。我确信Rails无法处理这个问题。 – spickermann

0

根据你的错误:

No route matches {:action=>"index" 

看来你试图访问index行动?

诚实,我不能让自己过的所有路由看(你可能要切出不相关的东西吗?)

你是如何调用带有link_to的路线?

+0

我刚刚编辑路线以剪掉不相关的位。这对我来说似乎也是这样,它试图访问'index'方法而不是'show'方法,但我不明白为什么或者它如何在那里结束。我们使用它来链接到每个对象:'link_to_document intellectual_object',其中'intellectual_object'是循环中的一个变量,用于保存当前正在呈现的智能对象。 – user3254621