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

Problem with impressionist gem #1315

Closed
benbruscella opened this issue Sep 10, 2012 · 17 comments
Closed

Problem with impressionist gem #1315

benbruscella opened this issue Sep 10, 2012 · 17 comments

Comments

@benbruscella
Copy link

If I try to use the impressionist gem with rails_admin, I get this:

gems/activerecord-3.2.8/lib/active_record/dynamic_matchers.rb:50:in `method_missing': undefined local variable or method `is_impressionable' for #<Class:0x007fa48e882658> (NameError)
  from app/models/user.rb:3:in `<class:User>'
  from app/models/user.rb:1:in `<top (required)>'
  from gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `load'
  from gems/activesupport-3.2.8/lib/active_support/dependencies.rb:469:in `block in load_file'
  from config/initializers/rails_admin.rb:9:in `block in <top (required)>'
  from gems/rails_admin-0.0.5/lib/rails_admin.rb:29:in `call'
  from gems/rails_admin-0.0.5/lib/rails_admin.rb:29:in `config'
  from config/initializers/rails_admin.rb:1:in `<top (required)>'

Is this a rails_admin issue or impressionist issue?

Gem home is https://github.com/charlotte-ruby/impressionist

@mshibuya
Copy link
Member

This appears to be related to #1185, and I can reproduce the problem for this time.

@benbruscella
Copy link
Author

Thanks for the update @mshibuya

@mshibuya
Copy link
Member

This is initialization order problem.

When using Impressionist(or Rolify) without RailsAdmin, app's initialization process should look like:

  • load and execute files in config/initializers/*.rb
  • ...
  • execute engines' initializers
  • ...
  • Rails loads model classes
    • User model is loaded

But, after the installation of RailsAdmin:

  • load and execute files in config/initializers/*.rb
    • load and execute config/initializers/rails_admin.rb, which refers to User model
      • so Rails loads User model, but Impressionist's AR extension is not loaded yet

so gives the error.

For workaround, you can eliminate reference of model classes from config/initializers/rails_admin.rb by moving configurations to your model class, as described in Wiki:

class User < ActiveRecord::Base
  ...

  rails_admin do
    field :name, ...
  end
end

But to solve this fundamentally, I need to be more familiarized with Rails initialization process.

@benbruscella
Copy link
Author

Any update on this? No luck moving my configuration to the model.

@mshibuya
Copy link
Member

Can you paste your RailsAdmin initializer here?

@benbruscella
Copy link
Author

  config.model User do
    object_label_method do
      :custom_label_method
    end
    list do
      items_per_page 100
      field :id
      field :name do
        formatted_value do
          bindings[:view].tag(:img, { :src => bindings[:object].photo_url(:icon32) }) << "  " << value 
        end
      end
      field :email
      field :sign_in_count
    end
  end

@benbruscella
Copy link
Author

I'm guessing "list" doesn't work in a model definition. Any other ideas?

@mshibuya
Copy link
Member

mshibuya commented Nov 6, 2012

What "doesn't work" means?

And I need full content of RailsAdmin initializer, not only config.model User block.
I want to make sure that early loading of User model doesn't occur throughout entire RA initializer.

@benbruscella
Copy link
Author

RailsAdmin.config do |config|

  config.current_user_method { current_user }

  config.main_app_name = ['The Transfer Station', 'Admin Dashboard']

  config.authorize_with :cancan, AdminAbility

  config.model User do
    object_label_method do
      :custom_label_method
    end
    list do
      items_per_page 100
      field :id
      field :name do
        formatted_value do
          bindings[:view].tag(:img, { :src => bindings[:object].photo_url(:icon32) }) << "  " << value 
        end
      end
      field :email
      field :sign_in_count
    end
    edit do
      exclude_fields :password, :password_confirmation, :reset_password_sent_at, :remember_created_at, :sign_in_count, 
        :current_sign_in_at,
        :last_sign_in_at,
        :current_sign_in_ip,
        :last_sign_in_ip,
        :confirmation_token,
        :confirmed_at,
        :confirmation_sent_at,
        :coaching,
        :speaking
    end
  end

  config.model Course do
    list do
      items_per_page 100
      field :id
      field :title
      field :user
      field :trainer
      field :hub
      field :category_and_region
      field :starts_at
      field :status
    end
    edit do
      exclude_fields :tags, :to_delete_published, :latitude, :longitude, :gmaps,:bookmarkables, :orders
    end
  end

  config.model Hub do
    list do
      items_per_page 100
      field :name do
        formatted_value do
          bindings[:view].tag(:img, { :src => bindings[:object].logo_url(:icon32) }) << "  " << value 
        end
      end
      field :email
      field :address
      field :website
    end
    edit do
      exclude_fields :hub_members, :trainers, :administrators, :primary_administrators, :bookmarkables
    end
  end


end

@mshibuya
Copy link
Member

mshibuya commented Nov 7, 2012

I've just tried again and moving configurations to model classes works.
How did you do that?
Can you paste RA initializer and User class after moving configs?

@benbruscella
Copy link
Author

Does this help at all?

#1428

@taavo
Copy link
Contributor

taavo commented Dec 31, 2012

Yeah, as described at the top of #1428, as long as you use 'User' instead of User, a regular initializer using config.model should defer model loading until well after initialization.

@benbruscella
Copy link
Author

Now we have:

[RailsAdmin] Could not load model User, assuming model is non existing. (undefined local variable or method `is_impressionable' for #<Class:0x007f97e34528d8>)

@benbruscella
Copy link
Author

did you want me to setup a fresh rails project for you to test this with?

@mshibuya
Copy link
Member

I'm sorry for being away from here.
Create one, please!

@benbruscella
Copy link
Author

Well, it seems to be fixed? Working repo:

https://github.com/benbruscella/raimpressionist

@davechisholm
Copy link

I'm having this same problem with the latest version of impressionist and rails admin as described here - http://stackoverflow.com/questions/24183344/conflict-between-rails-admin-and-impressionist-gems . I've tried the solutions mentioned here but still no luck - any ideas? It simply won't initialize when I have 'is_impressionable' in my model, so I have to keep commenting it out whenever I want to restart the server or generate a migration etc

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

No branches or pull requests

4 participants