当我打开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