在 _follow.html.slim 我试图用这个链接到“添加朋友”:
= link_to "Add Friend", :controller => "relationships", :action => "req"
我希望它在保持在同一页面上的同时调用关系控制器中的方法 req 。它目前甚至没有调用该方法并返回此错误:No route matches {:controller=>"relationships", :action=>"req", :name=>"Nathan Glass", :age=>"21 "}
我正在关注本教程http://francik.name/rails2010/week10.html并且他没有为此操作定义路线。如果这个错误是正确的,我想我的困惑就是为什么我需要一个路线。否则,我的问题是什么?谢谢!
class RelationshipsController < ApplicationController
def req
puts "req called"*10
# is setting @current_user since the current_user method already returns @current_user?
@current_user = current_user
@friend = User.find_by_name(params[:name])
unless @friend.nil?
if Relationship.request(@current_user, @friend)
flash[:notice] = "Friendship with #{@friend.name} requested"
else
flash[:error] = "Friendship with #{@friend.name} cannot be requested"
end
end
# render somewhere
end
结尾