Acts that can be used for public purposes

I am working on an application where people can love messages. I use a gem of community service and Acts As Votable.

I am getting this error when I try to view the page:

undefined method 'get_upvotes' for PublicActivity::Activity:0x00000101453ad8

      

Get_upvotes is supposed to have act_as_votable. What am I doing wrong?

User model

class User < ActiveRecord::Base
    acts_as_voter
end

      

Action model

class Activity < ActiveRecord::Base
    acts_as_votable
end

      

View Code

<% if activity.owner == current_user %>
    <i>This has been liked <strong><%= activity.get_upvotes.size %></strong> times</i>
<% else %>
    <%= link_to like_activity_path(activity),  class: "like", method: :put do %>
      <button type="button" class="btn btn-info" aria-label="Left Align">
        <span class="glyphicon glyphicon-thumbs-up glyphicon-align-center" aria-hidden="true"></span>
        <span class="badge"><%= activity.get_upvotes.size %></span>
      </button>
    <% end %> 
    <a class="btn btn-default btn-xs timeline-button"><i class="fa fa-heart"></i> I Liked This</a>
<% end %>

      

Operations controller

class ActivitiesController < ApplicationController

    before_action :authenticate_user!, only: [:index, :upvote]

    def index
        @users = current_user.active_friends
        @users.push(current_user)
        case params[:content] when 'posts'
            @activities = PublicActivity::Activity.where(owner_id: @users, trackable_type: "Post").paginate(page: params[:page], per_page: 6).order('created_at DESC')
        else
            @activities = PublicActivity::Activity.where(owner_id: @users).paginate(page: params[:page], per_page: 6).order('created_at DESC')
        end
    end

    def upvote
        @activity = Activity.find(params[:id])
        @activity.upvote_from current_user
        redirect_to activities_path
    end

end

      

Thanks for any help you can offer. I'm on the verge of knowing Rails. :)

+3


source to share


1 answer


The model Activity

is inside a module PublicActivity

, which means it should work.



class PublicActivity::Activity
  acts_as_votable
end

      

0


source







All Articles