0
我已經有一個設計問題,我張貼在這裏:Weird route malfunction, mix between devise and own controller
我希望這只是一次性問題,但設計讓我瘋狂!設計在我的導軌應用程序中創建故障
如果我做這一切都是確定
<% if user_signed_in? %>
<% if current_user.ideas.include?(@idea) %>
<%= button_to 'Remove from Favorites', user_idea_subscription(@idea.id), method: :delete%>
<% else %>
<%= button_to 'Add to Favorites', user_idea_subscriptions_path(current_user, :idea_id => @idea) %>
<% end %>
<% end %>
但是,如果我這樣做:
<% if user_signed_in? and current_user.ideas.include?(@idea) %>
<%= button_to 'Remove from Favorites', user_idea_subscription(@idea.id), method: :delete%>
<% else %>
<%= button_to 'Add to Favorites', user_idea_subscriptions_path(current_user, :idea_id => @idea) %>
<% end %>
然後我得到這個錯誤:
No route matches {:controller=>"idea_subscriptions", :idea_id=>#<Idea id: 12, name: "Chute libre", description: "50sec a 50m/s", created_at: "2012-07-12 10:02:30", updated_at: "2012-07-12 10:02:30">}
一切都應該是確定但爲什麼我得到這個錯誤? (旁邊沒有關於錯誤的其他信息)
感謝您的幫助和我的理智!
那好吧THX!我這樣做是因爲即使用戶沒有登錄,我想讓他看到添加收藏夾按鈕,但在控制器中,我將設置一個Flash通知「註冊以將想法添加爲收藏夾」並重定向到@idea。那我該怎麼做? – Pontek 2012-07-17 13:36:03
你不能使用這個路徑助手沒有user_id,所以你必須使用另一個路徑未經授權的用戶或只是使用一些JavaScript的「#無授權」網址。 – 2012-07-17 13:40:19