當我打開http://localhost:3000/users我得到以下路由錯誤:錯誤路由
No route matches {:action=>"req", :controller=>"friendship", :id=>"[email protected]"}
如何解決這個問題?
內部的用戶/ index.html.erb:
<ul>
<% @users.each do |user| %>
<li>
<%= user.full_name %>
(<%= link_to "request friendship",
:controller => :friendships,
:action => :req,
:id => user.email %>)
</li>
<% end %>
</ul>
內FriendshipsController
:
def req
@user = User.logged_in(session)
@friend = User.find_by_email(params[:id])
unless @friend.nil?
if Friendship.request(@user, @friend)
flash[:notice] = "Friendship with #{@friend.full_name} requested"
else
flash[:notice] = "Friendship with #{@friend.full_name} cannot be requested"
end
end
redirect_to :controller => :users, :action => :index
end
內的routes.rb:
resources :friendships
我想創建友誼model.when我打開http:// localhost:3000 /用戶它應該顯示所有註冊用戶和請求友誼鏈接在他們面前。點擊請求友誼它應該去友誼控制器請求action.but在點擊http:// localhost:3000/users – Nikita 2012-03-12 07:50:45
時,我在用戶的index.html.erb文件上出現錯誤「feedbacks」資源有什麼意義?你正在使用非RESTful動作('friendships#req'),你的routes.rb應該定義一些路徑來處理你對friendhsips控制器的請求:'get'friendships /:id'=>'friendships#req' '。 – Jef 2012-03-12 08:06:00
@ jef「反饋」資源誤寫了它..資源:友誼。 – Nikita 2012-03-12 08:35:38