2013-03-08 43 views
0

我有一個指導模型和評論模型,我試圖讓他們都可以跟蹤我的活動飼料。指南正在起作用,評論不是。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 

回答

0

如果我正確理解你的問題這個轉換說明它非常好: http://railscasts.com/episodes/406-public-activity的情況下,你還沒有看到它。

在我來說,我有Post模型(而不是你的Guidelines)和Comment和我剛添加

include PublicActivity::Model 
    tracked owner: Proc.new{ |controller, model| controller.current_user } 

PostComment模型和一切工作良好,沒有添加任何東西activities_controller

public_activity/comment/_create.html.erb

said "<%= activity.trackable.body.truncate(100) %>" on <%= link_to activity.trackable.commentable.title, project_post_path(activity.trackable.commentable.project, activity.trackable.commentable.id) %> post. 

public_activity /後/ _create.html.erb

added a new <%= link_to activity.trackable_type.downcase, project_post_path(activity.trackable.project, activity.trackable.id) %> to <%= link_to activity.trackable.project.title, project_path(activity.trackable.project) %> project. 

活動index.html.erb

<% @activities.each do |activity| %> 
    <%= link_to activity.owner.full_name, activity.owner if activity.owner %> 
    <%= render_activity(activity) %> 
<% end %> 
相關問題