2012-05-03 21 views
0

最後,我們爲我們的郵件生成了一個有用的鏈接。 generate an real url with rails for an e-mail 這工作得很好,非常好。但是,我們要調用的鞋行動:-)如何使用link_to rails顯示配置文件

<%=link_to('Link', :controller => 'mycontroller', :action => 'show', :id => @mycontroller.id)%> 

該URL所以

http://localhost:3000/mycontroller/show/10 

我們需要這種結構

http://localhost:3000/mycontroller/10 

rake routes命令說,這

mycontroller GET /mycontroller/:id(.:format)    mycontroller#show 

我們怎麼樣等所需的結構?我們是否需要編輯我們的路線,還是有另一種方法來獲得正確的網址?

+0

如何使你的'routes.rb'文件現在看起來?你能把它粘貼在這裏嗎? –

回答

2

嘗試使用路由幫助

mycontroller_url(@mycontroller.id) 

代替{:控制器=> ...,:動作=> ...}

您的link_to助手應該是這樣的更好的例子我使用的用戶展示行爲

耙路線返回此

user GET /users/:id(.:format) users#show 

,現在我知道我可以ü SE的user_url(@user)輔助

<%=link_to('Link', user_url(@user))%> 
+0

這有效,但還有其他錯誤。 ':only_path => false'不會被採用。網址看起來很「mycontroller /:id」,但沒有主機。 – amarradi

+0

你可以在這裏粘貼錯誤,也可以粘貼你的link_to助手嗎? – Suborx

+0

不是最好的解決方案是建立一個url而不是鏈接'<%= url_for(:action =>'show',:controller =>'wishlists',:only_path => false,:id => @wishlist。 ID)%>' – amarradi

相關問題