0

I am trying to make an app with Rails 4.

I have installed the public_activity gem.

I followed the Ryan Bates Railscast and took the controller based approach, and also the lighter Common option (as opposed to tracking the Model).

In my activities_controller I have:

class ActivitiesController < ApplicationController
  def index
      @activities = PublicActivity::Activity.order("created_at desc")
  end
end

In my project.rb, I have:

include PublicActivity::Common

In my projects controller, create action, I have:

@project.create_activity :create, owner: current_user

In my activity view - index, I have:

<% Activities.each do |activity| %>
        <div class="col-md-4">
          <div class="indexdisplay">

            <span class="indexheading"> 
              <%= link_to activity.owner.name, activity.owner if activity.owner %>
            </span>
            <span class="indexsubtext">                 
              <%= render_activity activity %>
            </span>

In my public activity (view folder)/project/_create.html.erb, I have:

<% if activity.trackable %>
  <%= link_to activity.trackable.name, activity.trackable %>
<% else %>
  which has since been removed
<% end %>

When I try this, I get this error:

NameError at /activities
uninitialized constant ActionView::CompiledTemplates::Activities

I tried replacing the opening line of the activity#index so that Activities, is Activity, but it just changed the error message to:

NameError at /activities
uninitialized constant ActionView::CompiledTemplates::Activities

What does this error mean? How do I fix it?

Thank you

Mel
  • 2,481
  • 26
  • 113
  • 273

2 Answers2

0

It should be <% Activity.find_each do |activity| %>

  1. Model name always is singular
  2. You cannot call each just on Model
  3. I'd recommend you use find_each instead of each in case you have a lot of records
  4. if you do want all the records you can always use .all method

http://apidock.com/rails/ActiveRecord/Batches/ClassMethods/find_each

Pynchia
  • 10,996
  • 5
  • 34
  • 43
Arsen
  • 10,815
  • 2
  • 34
  • 46
0

It seems like you use Class in your loop. Try to use your instance variable in your controller.

Change this

<% Activities.each do |activity| %>

into

<% @activities.each do |activity| %>
akbarbin
  • 4,985
  • 1
  • 28
  • 31