2013-05-16 63 views
0

我在第一次在我的rails应用程序上实现'follow功能'。我有饮食观和控制器。在这里,我想注册用户关注foodios。Rails:未定义的方法`follow_user_path'

我foodio控制器:

class FoodiosController < ApplicationController 

    def show 
    if params[:id].to_i.to_s == params[:id] 
      @foodio = User.find(params[:id]) 
    else 
      profile = Profile.find_by_brand_name(params[:id]) 
      if profile.nil? 
       profile = Profile.find_by_first_name(params[:id]) 
      end 
      @foodio = User.find(profile[:user_id]) 
    end 
    @products = @foodio.products.paginate(:page => params[:page]) 
    end 


    def follow 
     @user = User.find(params[:id]) 
     current_user.follow(@user) 
     respond_to do |format| 
     format.js {render :action=>"follow"} 
     end 
    end 

    def unfollow 
     @user = User.find(params[:id]) 
     current_user.stop_following(@user) 
     respond_to do |format| 
     format.js {render :action=>"unfollow"} 
     end 
    end 
    end 

在foodio视图,我有:

show.html.erb:

  <div id="follow_user<%[email protected]%>"> 
       <% unless @foodio == current_user %> 
       <% if current_user.following?(@foodio) %> 
        <%= link_to(unfollow_user_path(@foodio), :remote => true, :class => 'btn btn-primary') do %> 
        <i class="icon-remove icon-white"></i> 
        'Un-Follow' 
        <% end %> 
       <% else %> 
        <%= link_to(follow_user_path(@foodio) ,:remote => true, :class => 'btn btn-primary') do %> 
        <i class="icon-ok icon-white"></i> 
        'Follow' 
        <%end%> 
       <% end %> 
       <% end %> 
      </div> 

_follow_user.html.erb

<% unless @foodio == current_user %> 
    <% if current_user.following?(@foodio) %> 
    <%= link_to(unfollow_user_path(@foodio), :remote => true, :class => 'btn btn-primary') do %> 
    <i class="icon-remove icon-white"></i> 
    'Un-Follow' 
    <% end %> 
    <% else %> 
    <%= link_to(follow_user_path(@foodio) ,:remote => true, :class => 'btn btn-primary') do %> 
     <i class="icon-ok icon-white"></i> 
     'Follow' 
    <%end%> 
    <% end %> 
<% end %> 

follow.js.erb

$('#follow_user<%[email protected]%>').html('<%= escape_javascript(render :partial => "foodios/follow_user", :locals => {:user => @user}) %>'); 

unfollow.js.erb

$('#follow_user<%[email protected]%>').html('<%= escape_javascript(render :partial => "foodios/follow_user", :locals => {:user => @user}) %>'); 

,并在用户模型包括

acts_as_follower 
acts_as_followable 

在我的路线文件,我已经补充说:

resources :foodios do 
member do 
    get :follow 
    get :unfollow 
end 
end 

但我获取错误:

undefined method `follow_user_path on <%= link_to(follow_user_path(@foodio) ,:remote => true, :class => 'btn btn-primary') do %> in show.html.erb 

任何人都可以帮助我吗?

回答

0

你的路线不知道用户...他们只知道食物。 Try:

follow_foodio_path(@foodio)