Track updated params that have changed

136 views
Skip to first unread message

Justin Lewis

unread,
Aug 5, 2014, 1:16:10 AM8/5/14
to public-...@googlegroups.com
This works, but gives me all project_params. Any idea how I only pass in what params have changed?

@project.create_activity :update, owner: current_user, params: project_params

Piotrek Okoński

unread,
Aug 6, 2014, 9:32:54 AM8/6/14
to Justin Lewis, public-...@googlegroups.com
You can use ActiveModel::Dirty used by Rails => http://api.rubyonrails.org/classes/ActiveModel/Dirty.html

@person.changes # => {"name" => ["Bill", "Bob"]}


On 5 August 2014 07:16, Justin Lewis <jus...@weareinstrument.com> wrote:
This works, but gives me all project_params. Any idea how I only pass in what params have changed?

@project.create_activity :update, owner: current_user, params: project_params

--
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.



--
Piotr Okoński
pio...@okonski.org | +48 792 097 151

fabien piette

unread,
Dec 16, 2014, 12:07:44 PM12/16/14
to public-...@googlegroups.com
You can make like that, in the case you want to follow only attributes in particular:

def track_changing_attributes
  tracking_attributes = %w(name description estimated_time state).to_set
  if changed.to_set.intersect?(tracking_attributes)
    changed_scope_attribute = changes.select { |key, _| tracking_attributes.include? key }
    create_activity(
      action: 'update',
      parameters: {attributes: changed_scope_attribute},
      owner: lambda { |controller, _| controller.current_user }
    )
  end
end

Olivier S

unread,
Jan 22, 2015, 3:57:10 PM1/22/15
to public-...@googlegroups.com
I am passing previous_changes to Public_activity with parameters :

@user.create_activity key: 'user.modified', owner: current_user, parameters: @user.previous_changes
Reply all
Reply to author
Forward
0 new messages