Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow inject into header or footer of layout html markup or js code #2450

Closed
jalkoby opened this issue Sep 1, 2013 · 3 comments
Closed

Allow inject into header or footer of layout html markup or js code #2450

jalkoby opened this issue Sep 1, 2013 · 3 comments

Comments

@jalkoby
Copy link
Contributor

jalkoby commented Sep 1, 2013

I enjoy to use activeadmin, but also I like Gon gem which allow to transport some variables from ruby env to js. Gon requires to render helper method include_gon in view. But active_admin doesn't allow inject some html code into it layout, so I added dirty patch into my initializer https://gist.github.com/jalkoby/ead3b3a1febb2e8248ee.

It uses internal activeadmin and arbre methods with overriding footer builder of any page. It solves the problem, but solution is not good as it could be. I liked to have something like that in active_admin configuration

ActiveAdmin.setup do |config|
  config.content_for(:footer) do |view_context|
    view_context.concat(view_context.include_gon)
  end
end

Is it makes sense for anyone else? Maybe someone suggests more elegant way to solve my problem.

@seanlinsley
Copy link
Contributor

You can currently do this:

ActiveAdmin.setup do |config|
  config.view_factory.register footer: Footer
end

class Footer < ActiveAdmin::Component
  builder_method :footer

  def build
    # you have access to Arbre in here
  end
end

Is anything more complex really needed?

@jalkoby
Copy link
Contributor Author

jalkoby commented Sep 4, 2013

Thank you for answer. Yes, it's really nice way

@jalkoby jalkoby closed this as completed Sep 4, 2013
@mirelon
Copy link
Contributor

mirelon commented Sep 26, 2019

It is fragile. In ActiveAdmin 2 you need to add a parameter "namespace":

ActiveAdmin.setup do |config|
  config.view_factory.register footer: Footer
end

class Footer < ActiveAdmin::Component
  builder_method :footer

  def build(namespace)
    # you have access to Arbre in here
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants