Reputation: 1777
I have a custom page in ActiveAdmin called statistics, where I want to display charts with data from the database.
Now I used the Gon gem and want to pass the data to my custom page through an instance variable.
Usually you would add the gon line to the index action
class ProductsController < ApplicationController
def index
gon.rabl "app/views/products/index.json.rabl", as: "products"
end
end
But there is no controller in active admin for my custom page. How should I do this? Or do I have to do this through the dashboard?
Upvotes: 2
Views: 4404
Reputation: 1639
There is controller in active admin, despite this you can not pass instance variable to arbre part. But you can use params
hash for this:
ActiveAdmin.register_page 'SomePage' do
menu :label => 'Menu label'
controller do
def index
params[:some_var] = 'value_of_some_var'
end
end
content 'Page title' do
h2 "This is some_var: #{params[:some_var]}"
end
end
P.S.: If you don't want to change params
, then all instance variables are stored in @arbre_context.assigns
. You may also do like:
ActiveAdmin.register_page 'SomePage' do
menu :label => 'Menu label'
controller do
def index
@some_var = 'value_of_some_var'
end
end
content 'Page title' do
h2 "This is some_var: #{@arbre_context.assigns[:some_var]}"
end
end
Upvotes: 10
Reputation: 391
Is your custom page being rendered from a 'Resource' controller ie from a resource that you have created in you application? If yes, then that is a controller itself. You can defined any custom action in the controller for the same. And you can use the same strategy to pass data to your page as you do for partials ie by using the :locals
Upvotes: 1