How can you reference the instance of the object you are currently viewing?
The following WORKS
ActiveAdmin.register Example do
sidebar "test" do
@name = example.name
end
end
The following DOESN'T Work
ActiveAdmin.register Example do
member_action :some_stuff, :method => :put do
@name = example.name
end
end
How can I reference the object in the member_action?
Or will I have to create another instance?
You can use 'resource' object.
ActiveAdmin.register Example do
member_action :some_stuff, :method => :put do
@name = resource.name
end
end
Most of the active admin documentation is out of date or completely nonexistent. You will likely have to read the source and hope somebody commented functions if you want the nitty-gritty on how to use it.
The member_action function documentation is as follows:
# Member Actions give you the functionality of defining both the
# action and the route directly from your ActiveAdmin registration
# block.
#
# For example:
#
# ActiveAdmin.register Post do
# member_action :comments do
# @post = Post.find(params[:id]
# @comments = @post.comments
# end
# end
#
# Will create a new controller action comments and will hook it up to
# the named route (comments_admin_post_path) /admin/posts/:id/comments
#
# You can treat everything within the block as a standard Rails controller
# action.
#
This makes it look like they expect you to perform your own object lookup in custom actions - Post.find(params[:id]).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With