所以,我有一個名爲路線:動態路由不渲染
match 'ip/get/:ip' => 'ip_addresses#show', :via => :get
正如你所看到的,我想在IP(後「得到」)是動態的,但我不斷收到路由錯誤當我嘗試它。這裏是我的路線:
root / ip_addresses#index
ip_add POST /ip/add(.:format) ip_addresses#create
GET /ip/add(.:format) ip_addresses#new
ip_all GET /ip/all(.:format) ip_addresses#index
GET /ip/get/:ip(.:format) ip_addresses#show
DELETE /ip/all(.:format) ip_addresses#destroy
這是我的show
行動:
def show
IpAddress.find(params[:id])
end
編輯:路由錯誤:
ActionController::RoutingError (No route matches [GET] "/ip/get/1.2.3.4"):
我從外面看Rails的路由在指南( http://guides.rubyonrails.org/routing.html)但自然我可能會忽略某些東西。任何幫助表示讚賞。謝謝!
你能解釋一下你想完成什麼?看看代碼和路線,我懷疑這是解決這個問題的好辦法。雖然這不是你的答案的直接答案,但我可以建議更乾淨的代碼,這樣做是一樣的。 – Aleks 2013-03-27 13:04:54
你能分享你收到的錯誤嗎? – KULKING 2013-03-27 13:04:56
Aleks,我同意這可能會更清潔,但我基本上完成了一個編碼練習,它要求命名的路由是RESTful的,並且在#show的情況下是動態的。如果您對提供的代碼有任何建議,請隨時添加! – aceofbassgreg 2013-03-27 13:17:08