'From an ActiveAdmin Sidebar how can I know what action I am in?
I wrote a custom ActiveAdmin Sidebar that adds context sensitive documentation to all the entities in my app.
I'd like the Sidebar to know what is the current controller action so to display more relevant information. Most importantly I'd like to know if the action is :index vs the other object specific actions.
To give you some more context, in case the action is :index I'd like to display a text that explains what the entity is, and if the action is :new or :edit I'd like to show a detail of all the object properties.
The code below gives you an idea of what I'm trying to achieve
module Help
class HelpSidebar < ActiveAdmin::SidebarSection
@@help
def initialize
@@help = YAML.load(File.read("app/admin/help/help.yml"))
super "help", sidebar_options
end
def block
-> do
# if action == :index
text_node @@help
.dig(collection.klass.to_s, "text")
# else
ul do
@@help
.dig(collection.klass.to_s, "fields")
.each do |key, value|
li do
b "#{key.humanize}:"
text_node value
end
end
end
#end
end
end
def title
super
end
protected
def sidebar_options
{ if: proc { @@help.key?(collection.klass.to_s) } }
end
end
end
Thanks for your help
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
