two trakable id

48 views
Skip to first unread message

Andres Macedo

unread,
Apr 28, 2015, 10:11:15 PM4/28/15
to public-...@googlegroups.com
hi,

i am getting two activities for each request, 

#<PublicActivity::Activity:0x007fb0b139d870>

Andy just requested aFas

Posted a minute ago

#<PublicActivity::Activity:0x007fb0b139d168>

Andy just requested aFas

Posted a minute ago


I am not sure why

Piotrek Okoński

unread,
Apr 29, 2015, 5:22:58 AM4/29/15
to Andres Macedo, public-...@googlegroups.com
Can you post your model which you track? Are you using `create_activity` method, too?

--
You received this message because you are subscribed to the Google Groups "Public Activity" group.
To unsubscribe from this group and stop receiving emails from it, send an email to public-activi...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.



--

Andrés Rdz-Macedo

unread,
Apr 29, 2015, 5:48:15 AM4/29/15
to Piotrek Okoński, public-...@googlegroups.com
​hi piotrek thanks for the reply!
we are building an app for a friend of ours that is in nepal so I appreciate the reply...

I am using devise hence current_beneficiary..

here is all the code 

MODEL
class RequestedResource < ActiveRecord::Base
  include PublicActivity::Model
  tracked owner: Proc.new{ |controller, model| controller.current_beneficiary }


  has_many :claimed_resources
belongs_to :beneficiary
validates :name, :quantity, :urgency, presence: true

  def quantity_remaining
    amount_left = self.quantity
    self.claimed_resources.each do |resource|
      amount_left -= resource.quantity
    end
    amount_left
     # = self.quantity - self.claimed_resources[0].quantity
  end
end


application controller-------------------------------------

class ApplicationController < ActionController::Base
  include PublicActivity::StoreController
 ...

activities controller --------------------------------------------

class ActivitiesController < ApplicationController
  def index
    @activities = PublicActivity::Activity.all
  end
end

VIEW-----------------------------------------------


<h1>News Feed</h1>

<div class="activity">
     <% @activities.each_with_index do |activity, index| %>
         <p><%= link_to activity.owner.name, activity.owner if activity.owner %> just requested <%= activity.trackable.name %></p>
         <p><em>Posted <%= time_calc(activity.created_at.to_s)%></em></p>
    <% end %>
</div>

HELPERS ----------------------------------------------

module ActivitiesHelper

  def time_calc(created_at)

      time_now = Time.now.to_i
      time_reference = DateTime.parse(created_at).strftime('%s').to_i
      elapsed_time = time_now - time_reference

      case elapsed_time
        when 0 then 'just now'
        when 1 then 'a second ago'
        when 2..59 then '%d seconds ago' % elapsed_time.to_s
        when 60..119 then 'a minute ago' #120 = 2 minutes
        when 120..3540 then '%d minutes ago' % (elapsed_time/60).to_i.to_s
        when 3541..7100 then 'an hour ago' # 3600 = 1 hour
        when 7101..82800 then  '%d hours ago' % ((elapsed_time+99)/3600).to_i.to_s
        when 82801..172000 then 'a day ago' # 86400 = 1 day
        when 172001..518400 then  '%d days ago' % ((elapsed_time+800)/(60*60*24)).to_i.to_s
        when 518400..1036800 then 'a week ago'
        else '%d weeks ago' % ((elapsed_time+180000)/(60*60*24*7)).to_i.to_s

      end
    end
end



THANKS Again

Andy
--
Andrés Macedo

Andrés Rdz-Macedo

unread,
Apr 29, 2015, 1:21:24 PM4/29/15
to Piotrek Okoński, public-...@googlegroups.com
--
Andrés Macedo
Reply all
Reply to author
Forward
0 new messages