-
Hi team! I am rather new to Rails and I have just recently started using this gem for a website I'm building. Loving the design of the gem and how easy it has been to integrate it with my models! Reminds me of how easy it is to get up and running with Django's own built-in admin site. As I am diving deeper into customizing the site for my use case, I ran into a little bit of blocker regarding some of the abstractions that make the gem work: I am trying to customize the behavior of a controller, much like how you would a regular controller. In this specific case, I have an articles controller where I'd like to override the author attribute of a new article resource with the current user instead of letting the logged in administrator select a user record from the database. In a regular rails controller I'd have done something like the following:
However, there are a few layers of abstraction in the So, all of that to say: how could I go about implementing such a feature? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 1 reply
-
It's pretty straightforward! When you generate a resource, it will generate a matching controller that you can override as needed. For example Refer to the resources_controller to see what you have accessible and how the normal |
Beta Was this translation helpful? Give feedback.
It's pretty straightforward! When you generate a resource, it will generate a matching controller that you can override as needed.
For example
rails g madmin:resource Post
generatesapp/controllers/madmin/posts_controller.rb
. You can override the create action there.Refer to the resources_controller to see what you have accessible and how the normal
create
action looks: https://github.com/excid3/madmin/blob/master/app/controllers/madmin/resource_controller.rb