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

Document adding view helpers #3671

Closed
crystalneth opened this issue Dec 3, 2014 · 1 comment
Closed

Document adding view helpers #3671

crystalneth opened this issue Dec 3, 2014 · 1 comment

Comments

@crystalneth
Copy link

Could someone in-the-know please add to the documentation the proper way to add helper methods to views.

There are many proposed solutions out there on SO and elsewhere, none of which seem to work reliably in different cases and across AA versions.

For instance, let's say I want to add a method link_to_if_authorized to use in index and show pages. What is the right way to do this? I have tried a number of methods.

  index do
    column :slug do |plan|
      link_to_if_authorized [:edit, plan], plan.slug, edit_admin_plan_path(plan)
    end
@timoschilling
Copy link
Member

Using helpers in AA works out of the box:

module ApplicationHelper
  def foo(string)
    "foo: #{string}"
  end
end

  index do
    column :test do |object|
      foo object.name
    end
  end

renders a column with 'foo: bar' for example.

There are two possible sources for your problem:

  1. You have configured config.action_controller.include_all_helpers = false:
    1. Don't do it!
    2. You need to include the helper by hand:
      1. Include it in the ActiveAdmin::BaseController, I prefer a initializer with ActiveAdmin::BaseController.class_eval { helper ApplicationHelper }.
      2. Use controller { helper ApplicationHelper } in the related ActiveAdmin resource definition
  2. You ran into ApplicationController and Helpers are not being reloaded in Dev Env #697, if yes you need to restart your dev server each time you change a helper

timoschilling added a commit that referenced this issue Dec 4, 2014
varyonic pushed a commit to varyonic/activeadmin-rails that referenced this issue Dec 24, 2016
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

2 participants