Interior Night
Interior Night

Reputation: 1225

Problem with customising the follow functionality from chapter 12 of railstutorial.org

I'm trying to implement the follow functionality from chapter 12 of Michael Hartl's Ruby on Rails tutorial but i'm new to Rails and i fear i've bitten off more than i can chew.

My app uses devise and contains Posts, Responses and Comments rather than the microposts from the earlier chapters of the tutorial. I'd like to be able to see the posts, responses and comments of users when they are followed.

As it now stands, with the simple hacks i've done, the views are all in order and the app is not throwing up any visible errors.

The follow button is not working though and I'm getting the following error in the terminal:

NameError (undefined local variable or method `authenticate' for #<RelationshipsController:0x000001049ee238>):

What modifications should i do to the code provided in chapter 12 in order to get it working with my app? Any help would be most appreciated!

Edit:

Here is the code of my relationship controller:

class RelationshipsController < ApplicationController
  before_filter :authenticate

  def create
    @user = User.find(params[:relationship][:followed_id])
    current_user.follow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end

  def destroy
    @user = Relationship.find(params[:id]).followed
    current_user.unfollow!(@user)
    respond_to do |format|
      format.html { redirect_to @user }
      format.js
    end
  end
end

Upvotes: 1

Views: 305

Answers (1)

Interior Night
Interior Night

Reputation: 1225

Here is the answer to my question. Thanks to JCorcuera for twice pointing me in the right direction. Aside from changing :authenticate to :authenticate_user! i also had to change the create.js.erb and destroy.js.erb files to a jquery friendly syntax as per this answer: Rails 3 : prototype to jquery question.

Upvotes: 1

Related Questions