I have a simple rails app and i am trying to add an activity feed on it. For that i am using the Public Activity Gem and was following the this Railscast
but now it's giving me an error:
undefined method `shipment' for #<Shipment:0x6a96578>
My codes are:
activities_controller.rb
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
My Activity index.html.erb file
<h1>feeds</h1>
<% @activities.each do |activity| %>
<div class="activity">
<%= link_to activity.owner.full_name, activity.owner if activity.owner %>
added comment to <%= link_to activity.trackable.shipment.name.activity.trackable.shipment %>
</div>
<% end %>
My comment.rb file
class Comment < ActiveRecord::Base
include PublicActivity::Model
tracked owner: ->(controller, model) { controller && controller.current_user }
belongs_to :shipment
belongs_to :user
end
I have a simple rails app and i am trying to add an activity feed on it. For that i am using the Public Activity Gem and was following the this Railscast
but now it's giving me an error:
undefined method `user_path' for #<#:0x4a90a30>
My codes are:
activities_controller.rb
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
My Activity index.html.erb file
<h1>feeds</h1>
<% @activities.each do |activity| %>
<div class="activity">
<%= link_to activity.owner.full_name, activity.owner if activity.owner %>
added comment to <%= link_to activity.trackable.shipment.name.activity.trackable.shipment %>
</div>
<% end %>
My comment.rb file
class Comment < ActiveRecord::Base
include PublicActivity::Model
tracked owner: ->(controller, model) { controller && controller.current_user }
belongs_to :shipment
belongs_to :user
end
My routes.rb file
Rails.application.routes.draw do
get 'activities/index'
get 'profiles/show'
get 'pages/homepage'
devise_for :users, :controllers => {:registrations => "registrations"}
resources :shipments do
member do
get "like", to: "shipments#upvote"
end
resources :comments
end
# The priority is based upon order of creation: first created -> highest priority.
# See how all your routes lay out with "rake routes".
root "shipments#index"
get '/:id', to: 'profiles#show'
get "mailbox/inbox" => "mailbox#inbox", as: :mailbox_inbox
get "mailbox/sent" => "mailbox#sent", as: :mailbox_sent
get "mailbox/trash" => "mailbox#trash", as: :mailbox_trash
resources :conversations do
member do
post :reply
post :trash
post :untrash
resources :users
end
end
end
stack trace
Rendered activities/index.html.erb within layouts/application (31.2ms)
Completed 500 Internal Server Error in 109ms (ActiveRecord: 78.0ms)
ActionView::Template::Error (undefined method `shipment' for #<Shipment:0x4dc44b
0>):
2: <% @activities.each do |activity| %>
3: <div class="activity">
4: <%= link_to activity.owner.profile_name, activity.owner if activity.o
wner %>
5: added comment to <%= link_to activity.trackable.shipment.name, activi
ty.trackable.shipment %>
6: <% end %>
app/views/activities/index.html.erb:5:in `block in _app_views_activities_index
_html_erb___51428318_40366872'
app/views/activities/index.html.erb:2:in `_app_views_activities_index_html_erb
___51428318_40366872'