How to setup the follow/unfollow/block link_to button for Acts_As_Follower Rails 4

I'm currently in the process of completing the setup for the
acts_as_follower gem for Rails 4. When I click on the follow button, the
ActionView Exception Missing Template kicks in. Does anyone know how to
create a multi-state Zurb Foundation button for it or even custom radius
button. Simply: "Follow/Unfollow" If you have a better approach, please
share it. These solutions are necessities to development.

https://github.com/tcocca/acts_as_follower

Missing template users/follow, application/follow with {:locale=>[:en],
:formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw,
:ruby, :coffee, :slim, :haml, :jbuilder]}. Searched in:

<%= link_to 'Follow', follow_user_path(@user), class: 'button success
radius small' %>

def follow
    @user = User.friendly.find(params[:id])
    if current_user
      if current_user == @user
        flash[:error] = 'You cannot follow yourself.'
      else
        current_user.follow(@user)
        flash[:notice] = "You are now following #{@user.username}"
      end
    else
      flash[:error] = "You must be logged in to follow
#{@user.username}."
      redirect_to :back
    end
  end

  def unfollow
    @user = User.friendly.find(params[:id])
    if current_user
    current_user.stop_following(@user)
      flash[:notice] = "You are no longer following #{@user.username}."
    else
      flash[:error] = "You must be logged in to unfollow
#{@user.username}."
      redirect_to user_path(@user)
  end
  end

  def block
    @user = User.friendly.find(params[:id])
    if current_user
      current_user.block(@user)
      flash[:notice] = "You have blocked #{@user.username}."
      redirect_to user_path(@user)
    else
      flash[:notice] = "You aren't following #{@user.username}."
    end
  end

If you created an AJAX solution with the buttons before? Please post the
snippets while explaining your best practice method.

If you created an AJAX solution with the buttons before? Please post the
snippets while explaining your best practice method.

Please post the output of rake routes in your terminal here. It appears as though the gem should be hooking in a route to handle the click, but your Rails app didn't pick it up. Also, did you restart your app after adding the gem and running bundle install?

Walter

[GET] /users/:id/follow - follow_user
[GET] /users/:id/unfollow - unfollow_user

JS
_create.js.erb
$('#follow_user').html('<%= escape_javascript(render :partial =>
'follow_user', :locals => {:user => @user}) %>');

//JQuery

_destroy.js.erb
$('#follow_user').html('<%= escape_javascript(render :partial =>
'follow_user', :locals => {:user => @user}) %>');

//JQuery

_follow_user.html.erb

<% unless current_user %>
    <% if current_user.following?(user) %>
        <%= link_to "Unfollow #{user.username}",
unfollow_user_path(user), :method => :delete, :remote => true %>
    <% else %>
        <%= link_to "Follow #{user.username}", follow_user_path(user),
class: 'button success radius small', :method => :post, :remote => true
%>
    <% end %>
<% end %>

render link
<%= render 'users/follow_user' %>

Routes

resources :users, :only => [:show] do
    member do
      get :follow
      get :unfollow
      post :follow
      post :unfollow
      get :block
      get :followers
      get :following
      get :posts
    end
  end

A message shows you aren't currently following <yourself> constantly.

I'm using the latest version of Acts_As_Follower Gem. Can you help me
structure the solution better. Thanks

It cannot find a follow.html.erb template view.

Missing template users/follow, application/follow with {:locale=>[:en],
:formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw,
:ruby, :coffee, :slim, :haml, :jbuilder]}. Searched in:

It cannot find a follow.html.erb template view.

Woops, clicked enter by mistake.

The error comes because it's looking for a file `follow.html.erb` in your
app/views/<controller>/ directory. In your `follow` method, you do not
direct it anywhere, or tell it to render any other view, so that's what
it's looking for. Did you want it to go somewhere else?

def follow

    @user = User.friendly.find(params[:id])
    if current_user
      if current_user == @user
        flash[:error] = 'You cannot follow yourself.'
      else
        current_user.follow(@user)
        flash[:notice] = "You are now following #{@user.username}"
      end
    else
      flash[:error] = "You must be logged in to follow
#{@user.username}."
      redirect_to :back
    end
  end

The only redirect in that method happens if there is no logged in user. The
rest of it sets the flash, then falls through to the standard render.

By convention, a controller action will render a template with the same
name as the action plus the format extension (html in this case) and
handlers.

I'm in need of the AJAX method that allows a person to follow without
rendering a view.

I'm in need of the AJAX method that allows a person to follow without
rendering a view.

Initially you wanted to use a `link_to` to display the link someone would
click on to indicate they wanted to follow someone.

<%= link_to 'Follow', follow_user_path(@user), class: 'button success

radius small' %>

You'll need to change this into an AJAX request rather than a link_to. You
could probably use `button_tag` but you'll still need to write the actual
AJAX JavaScript code yourself for it. It's pretty straight-forward in
jQuery, attaching a callback to the click event on the button, and the
callback function does the AJAX request.

On the server side, if you really wish to render nothing at all, `render
nothing: true` will do that. See <
http://guides.rubyonrails.org/layouts_and_rendering.html#using-render>.

tamouse m. wrote in post #1176466:

In your link_to declaration, add remote: true in the options, and in your controller, add a handler for format.js alongside the format.html in the respond_to block. In that handler's block, tell it what to do. The simplest thing is to render a follow.js.erb, which can contain any JavaScript you like to note to the user that the follow event happened. Change the text of the button to "Following" for example. Add and remove a CSS class to "flash" the button or whatever else makes sense to your users.

Walter