I want to log the user who destroyed a record using before_destroy callback.
But, I dont know how to pass arguments to before_destroy(and I am not sure
if it is possible). Maybe I am dealing this in the wrong way. Any other
perspective to do this will also do.

--
Thanks,
Prince

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Prince Joseph at Feb 6, 2012 at 6:39 am
    I got it. I can add a virtual attribute to the model (something like
    `attr_accessor :destroyer` or something) and you can access it in the
    method for `before_destroy` callback. Something like:

    Controller

    @record = Record.find(params[:id])
    @record.destroyer = current_user
    @record.destroy

    Model

    attr_accessor :destroyer
    before_destroy :log_destroyer

    def log_destroyer
    if destroyer
    ## code for logging
    end
    end

    Courtesy: Azolo <http://stackoverflow.com/users/527152/azolo> who answered
    my question<http://stackoverflow.com/questions/9156088/log-the-user-who-destroyed-a-record-using-before-destroy-callback>
    in
    SO. In case anyone is wondering how to do it ;)
    On Mon, Feb 6, 2012 at 11:26 AM, Prince Joseph wrote:

    I want to log the user who destroyed a record using before_destroy callback.
    But, I dont know how to pass arguments to before_destroy(and I am not
    sure if it is possible). Maybe I am dealing this in the wrong way. Any
    other perspective to do this will also do.

    --
    Thanks,
    Prince

    --
    Thanks,
    Prince

    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedFeb 6, '12 at 5:56a
activeFeb 6, '12 at 6:39a
posts2
users1
websiterubyonrails.org
irc#RubyOnRails

1 user in discussion

Prince Joseph: 2 posts

People

Translate

site design / logo © 2021 Grokbase