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

Not a symbol. #313

Closed
CraneWing opened this issue Jul 1, 2015 · 3 comments
Closed

Not a symbol. #313

CraneWing opened this issue Jul 1, 2015 · 3 comments

Comments

@CraneWing
Copy link

I am using CPK so that I can edit a join table in Active Admin. I have a table category_recipes, with two columns, recipe_id and category_id. This is the model I am using for the table's index page in Active Admin.

require 'composite_primary_keys'

ActiveAdmin.register CategoryRecipe do

   form do |f|
      f.semantic_errors
      inputs 'Catgory Recipes' do
         input :category_id
         input :recipe_id
      end
      f.submit
   end

   remove_filter :category
   remove_filter :recipe

   permit_params :category_id, :recipe_id
end

My exact error is ["category_id", "recipe_id"] is not a symbol.

The error is being thrown in Active Admin's display_helper, in this block:

    module DisplayHelper

      DISPLAY_NAME_FALLBACK = ->{

        name, klass = "", self.class
        name << klass.model_name.human         if klass.respond_to? :model_name
        name << " ##{send(klass.primary_key)}" if klass.respond_to? :primary_key
        name.present? ? name : to_s

      }

Using Rails 4.2, ActiveRecord 4.2, composite_primary_keys 8.1.0.

@cfis
Copy link
Contributor

cfis commented Aug 5, 2015

You have to setup the model to have a composite key. That is generally done like this:

class MyClass
self.primary_keys = [:id1, :id2]
end

@cfis cfis closed this as completed Aug 5, 2015
@CraneWing
Copy link
Author

I have that exactly in my code, as the documentation says, but I still get the error.

@IMhide
Copy link

IMhide commented Nov 24, 2015

I had the exact same error.

When you look at the stack can see that it comes from the generated title

["user_id", "project_id"] is not a symbol


activeadmin (1.0.0.pre2) lib/active_admin/view_helpers/display_helper.rb:8:in `block in <module:DisplayHelper>'
activeadmin (1.0.0.pre2) lib/active_admin/view_helpers/method_or_proc_helper.rb:86:in `instance_exec'
activeadmin (1.0.0.pre2) lib/active_admin/view_helpers/method_or_proc_helper.rb:86:in `render_in_context'
activeadmin (1.0.0.pre2) lib/active_admin/view_helpers/display_helper.rb:18:in `display_name'
arbre (1.0.3) lib/arbre/element.rb:180:in `method_missing'
activeadmin (1.0.0.pre2) lib/active_admin/views/pages/show.rb:36:in `default_title'
--> activeadmin (1.0.0.pre2) lib/active_admin/views/pages/show.rb:14:in `title' <--
[...]

You can simply fix it by overriding the page title of the ActiveAdmin Ressource view this way :

controller do
  def show
    @page_title = "Awesome Title"
  end
end

Now ActiveAdmin works well with composite-primary-key

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