Created
June 26, 2012 17:26
-
-
Save croaky/2997233 to your computer and use it in GitHub Desktop.
Activity Feed pattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%ul | |
- activities.each do |activity| | |
%li | |
.activity{ data: { role: activity.activity_type } } | |
= render_activity activity |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#{user_path(bid.user)} offered a bid of #{bid.amount.format} for your job, #{bid_path(bid)}. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Activity < ActiveRecord::Base | |
belongs_to :subject, polymorphic: true | |
belongs_to :user | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module ApplicationHelper | |
def render_activity(activity, user = current_user) | |
activity_type = activity.activity_type | |
subject = activity.subject | |
partial = "activities/#{activity_type}" | |
subject_type = activity.subject_type.underscore.to_sym | |
render partial, subject_type => subject | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BidOfferedJob < Struct.new(:bid_id) | |
PRIORITY = 1 | |
def self.enqueue(bid) | |
Delayed::Job.enqueue new(bid.id), priority: PRIORITY | |
end | |
def perform | |
Mailer.bid_offered(owner, bid).deliver | |
Activity.create activity_type: 'bid_offered', subject: bid, user: owner | |
end | |
private | |
def bid | |
Bid.find bid_id | |
end | |
def owner | |
bid.job.owner | |
end | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class RenameActivityNotifications < ActiveRecord::Migration | |
def up | |
create_table :activities do |t| | |
t.timestamps null: false | |
t.integer :user_id, null: false | |
t.integer :subject_id, null: false | |
t.string :subject_type, null: false | |
t.string :activity_type, null: false | |
end | |
add_index :activities, :user_id | |
add_index :activities, :subject_id | |
add_index :activities, :subject_type | |
end | |
def down | |
drop_table :activities | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment