路由错误

时间:2012-03-12 07:38:04

标签: ruby-on-rails rails-routing

当我打开http://localhost:3000/users时,我收到了以下路由错误:

No route matches {:action=>"req", :controller=>"friendship", :id=>"admin@ascratech.com"}

如何解决这个问题?

内部用户/ 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

inside routes.rb:

resources :friendships

2 个答案:

答案 0 :(得分:0)

也许你想要做:

resources :friendships do
  member do
    get :req
  end
end

答案 1 :(得分:0)

它认为...... 设置方式,Rails将尝试获取资源 /友情/ REQ / ID 如果你想要第1,第3或第22个请求,它会期望id告诉它。

但你已经给了它     :ID =&GT;&#34; admin@ascratech.com" Rails正在寻找一个数字,你给它一个字符串。