0

I am implementing 'follow feature' on my rails app first time. I have foodio view and controller. Here i want signed up user to follow foodios.

My foodio controller:

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

In foodio view, i have:

show.html.erb:

            <div id="follow_user<%=@foodio.id%>">
              <% 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<%=@user.id%>').html('<%= escape_javascript(render :partial => "foodios/follow_user", :locals => {:user => @user}) %>');

unfollow.js.erb

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

And included in user model

acts_as_follower
acts_as_followable

In my routes file, i have added:

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

But i am getting error:

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

Can anyone help me in this?

4

1 回答 1

0

您的路线不了解用户......他们只了解 foodios。尝试:

follow_foodio_path(@foodio)
于 2013-05-16T07:08:53.447 回答