railsadminteam / rails_admin

RailsAdmin is a Rails engine that provides an easy-to-use interface for managing your data
MIT License
7.89k stars 2.26k forks source link

Feature Request: Callbacks and Filters #1293

Open ehoch opened 12 years ago

ehoch commented 12 years ago

What do you guys think of "borrowing" the idea of callbacks and filters from activeadmin? You can see the comments in their code

For starters, this will definitely clean up the hack I'm using for assigning the user via a default. (It's kind of a security nightmare since I use that for my authorization and have to enable user_id in my mass assignment)

Any ideas on how we could accomplish this via rails_admin's DSL? We don't really have the concept of the "controllers" that AA has. So maybe use Proc?

So I guess my proposal would be:

config.model Post do
  before_build do
    Proc.new do
      @object.user_id = bindings[:view]._current_user.id
    end
  end
end

It's not the most graceful thing, but seems like it might be the most doable given our current DSL? Thoughts? We could easily then replicate the various active record ones...

Then a similar-ish thing for filters?

ignasio commented 9 years ago

Is there any ways to get such behaviour now?

nickhoffman commented 6 years ago

As far as I know, the only way to do this right now is by using the callbacks that ActiveRecord provides.