Change history.

3 views
Skip to first unread message

Jose Donizetti

unread,
Sep 28, 2011, 8:48:21 AM9/28/11
to fulcru...@googlegroups.com
Hello everyone, I've started to code the change history feature which was discussed at https://github.com/malclocke/fulcrum/issues/38
and got stuck with a doubt.

The story_observer.rb is the one creating changesets with the after_save callback but now with he history idea changesets
will have the user who has done something on the history (created,changed,deleted). So I was wondering what could I do
to have the current_user (from devise) at the story_observer so that I could keep creating changesets there and just add
the current_user to it, but I haven't seen many ways of doing that, so I decided that to extracted the changeset creating
to the story_controller.rb and would like to hear some feedback of you! Thanks.

Regards,
José Donizetti.

Malcolm Locke

unread,
Sep 28, 2011, 6:54:10 PM9/28/11
to fulcru...@googlegroups.com

The StoriesController sets story.acting_user on the story from the
update action, and this is available to you in the StoryObserver.

https://github.com/malclocke/fulcrum/blob/master/app/controllers/stories_controller.rb#L25

You'll see the StoryObserver already accesses this field when
determining whether it needs to send email or not.

This currently only gets set on stories#update, so you'll probably want
to move @story.acting_user = current_user to a filter or method and call
it on create and destroy as well.

Also, make sure that Changeset.user_id is not a required field, i.e.
allow it to be nil. There will be some operations in future that run
via cron that will create changesets, but won't have a user associated
with them.

Hope that helps,

Malc

Jose Donizetti

unread,
Sep 28, 2011, 10:28:15 PM9/28/11
to fulcru...@googlegroups.com
Sure it help, didn't see it. I was focusing on the create method, and now I'm wondering why it don't persist the acting user as well.
Am I missing it again? Thank you for your help.

Malcolm Locke

unread,
Sep 29, 2011, 5:43:24 AM9/29/11
to fulcru...@googlegroups.com
On Wed, Sep 28, 2011 at 11:28:15PM -0300, Jose Donizetti wrote:
> Sure it help, didn't see it. I was focusing on the create method, and now
> I'm wondering why it don't persist the acting user as well.
> Am I missing it again? Thank you for your help.

Acting user doesn't need to be persisted on the story, but it will now
need to be persisted on the changeset. So, you'll need to:

- Migrate a user_id field onto changesets, and add belongs_to :user to
the Changeset model.
- Set acting user on the story in stories#create and stories#destroy in
StoriesController
- Assign the story.acting_user when creating a Changeset in
StoryObserver.

If you commit that on a branch I reckon that will be a good first step.

Malc

Reply all
Reply to author
Forward
0 new messages