我有一个简单的 Rails 应用程序,我正在尝试在其上添加活动源。为此,我正在使用 Public Activity Gem 并关注此Railscast
但现在它给了我一个错误:
undefined method `shipment' for #<Shipment:0x6a96578>
我的代码是:
活动控制器.rb
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
我的活动 index.html.erb 文件
<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 %>
我的comment.rb 文件
class Comment < ActiveRecord::Base
include PublicActivity::Model
tracked owner: ->(controller, model) { controller && controller.current_user }
belongs_to :shipment
belongs_to :user
end
我有一个简单的 Rails 应用程序,我正在尝试在其上添加活动源。为此,我正在使用 Public Activity Gem 并关注此 Railscast
但现在它给了我一个错误:
#<#:0x4a90a30> 的未定义方法“user_path”
我的代码是:
活动控制器.rb
class ActivitiesController < ApplicationController
def index
@activities = PublicActivity::Activity.order("created_at desc")
end
end
我的活动 index.html.erb 文件
<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 %>
我的comment.rb 文件
class Comment < ActiveRecord::Base
include PublicActivity::Model
tracked owner: ->(controller, model) { controller && controller.current_user }
belongs_to :shipment
belongs_to :user
end
我的 routes.rb 文件
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
堆栈跟踪
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'