我有一個指導模型和評論模型,我試圖讓他們都可以跟蹤我的活動飼料。指南正在起作用,評論不是。public_activity模型
的兩個主要問題是:
我不確定如何添加「評論」作爲activities_controller.rb第二trackable_type,我不知道該如何排序我的意見/ _create.rb觀點 - 應該說在x指南中添加了評論(並鏈接了指南顯示頁面)。
guidelines.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
comments.rb
include PublicActivity::Model
tracked owner: ->(controller, model){controller && controller.current_user}
belongs_to :guideline
belongs_to :commenter, class_name: 'User'
activities_controller.rb
def index
@activities = PublicActivity::Activity
.order("created_at desc")
.where(trackable_type: 'Guideline' 'Comment')
的意見/ public_activity /評論/ _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 /準則/ _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