2014-04-04 51 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