我有一个指南模型和一个评论模型,我试图让它们都可以在我的活动提要中进行跟踪。指导方针有效,评论无效。
2个主要问题是:
我不确定如何在activity_controller.rb 中添加“评论”作为第二个trackable_type,我不确定如何在comment/_create.rb 中对我的视图进行排序——它应该说评论已添加到x 指南(和链接该指南显示页面)。
指南.rb
include PublicActivity::Model
tracked owner: ->(controller, model){controller && controller.current_user}
attr_accessible :content, :hospital, :title, :user_id, :guideline_id, :specialty, :updated_by, :current_user, :subtitle, :slug, :activities, :comment
belongs_to :user
has_many :favourite_guidelines
has_many :comments, :dependent => :destroy
评论.rb
include PublicActivity::Model
tracked owner: ->(controller, model){controller && controller.current_user}
belongs_to :guideline
belongs_to :commenter, class_name: 'User'
活动控制器.rb
def index
@activities = PublicActivity::Activity
.order("created_at desc")
.where(trackable_type: 'Guideline' 'Comment')
意见/public_activity/comment/_create.html.erb
added a comment
<% if activity.trackable %>
to the guideline <%= link_to activity.trackable.body, activity.trackable %>
<% else %>
which can no longer be viewed
<% end %>
意见/public_activity/guideline/_create.html.erb
added a guideline
<% if activity.trackable %>
titled <%= link_to activity.trackable.title, activity.trackable %>
<% else %>
which can no longer be viewed
<% end %>
我的 routes.rb 是
Guidelines::Application.routes.draw do
get "activities/index"
# get "user/index"
ActiveAdmin.routes(self)
devise_for :admin_user, ActiveAdmin::Devise.config
get "guidelines/topic"
get "guidelines/topichospital"
get "guidelines/topicspecialty"
get "guidelines/favourite"
get "profiles/show"
get "guidelines/show"
devise_for :users
devise_scope :user do
get 'signup', to: 'devise/registrations#new', as: :register
get 'login', to: 'devise/sessions#new', as: :login
get 'logout', to: 'devise/sessions#destroy', as: :logout
get 'edit', to: 'devise/registrations#edit', as: :edit
put 'users' => 'devise/registrations#update', :as => 'user_registration'
get 'about', to: 'about#about', as: :about
end
resources :guidelines
get 'guidelines', to: 'guidelines#index', as: :guidelines
get 'favourites', to: "favourites#show", as: :favourites
get 'topics', to: 'guidelines#list', as: :topics
get 'hospitals', to: 'guidelines#listhospital', as: :hospitals
get 'specialties', to: 'guidelines#listspecialty', as: :specialties
resources :activities
root :to => 'guidelines#index'
resources :guidelines do
resources :comments
end