简体   繁体   English

Rails Admin和印象派宝石之间的冲突

[英]Conflict between Rails Admin and Impressionist gems

I'm using the latest version of the Impressionist and Rails Admin gems, and wondering if anyone could shed some light on an annoying conflict I'm experiencing. 我正在使用Impressionist和Rails Admin宝石的最新版本,并想知道是否有人能够揭示我正在经历的令人讨厌的冲突。 The problem is roughly documented here - https://github.com/sferik/rails_admin/issues/1315 , yet the vaguely described solution is not working for me. 问题大致记录在这里 - https://github.com/sferik/rails_admin/issues/1315 ,但模糊描述的解决方案对我不起作用。 When I have the line is_impressionable in my Listing model, I get an error when starting my Rails server with rails s: 当我的清单模型中有is_impressionable行时,在使用rails s启动Rails服务器时出错:

    ...rvm/gems/ruby-2.0.0-p247/gems/activerecord-4.0.2/lib/active_record/dynamic_matchers.rb:22:in `method_missing': undefined local variable or method `is_impressionable' for Listing(no database connection):Class (NameError)

If I first start the server, and then add the 'is_impressionable' line, everything works fine, so the problem only occurs during initialization. 如果我首先启动服务器,然后添加'is_impressionable'行,一切正常,所以问题只发生在初始化期间。 I don't fully understand the initialization process, so am not sure how to go about getting this to work. 我不完全理解初始化过程,所以我不确定如何让它工作。

I have tried moving all my rails_admin model configuration options to their respective models, rather than in the initializer, which had no effect. 我已经尝试将所有我的rails_admin模型配置选项移动到它们各自的模型,而不是在初始化程序中,它们没有任何效果。 I also have the following line in my initializer: 我的初始值设定项中还有以下行:

    config.included_models = [Listing,ListingImage,AllOtherModelsHere...]

I have tried adding single quotes around these model names, which results in the following errors, as described in the github issue here 我曾试图围绕这些模型的名称,这会导致下面的错误添加单引号,因为在GitHub的问题描述在这里

    [RailsAdmin] Could not load model Listing, assuming model is non existing. (undefined local variable or method `is_impressionable' for Listing(no database connection):Class)

Any ideas what else I can try to make these gems work together? 还有什么想法我可以尝试让这些宝石一起工作吗? I don't want to have to remove the is_impressionable line every time I want to restart the server or generate a migration... 每次我想重新启动服务器或生成迁移时,我都不想删除is_impressionable行...

Not sure if the same issue that I had but yet I will post what worked for me just in case someone struggles with this too: 不确定我是否有同样的问题,但我会发布对我有用的东西,万一有人也在努力解决这个问题:

Im on a ruby 2.1.5 project with rails 4.2.0 and among other gems I'm using rails admin. 我正在使用rails 4.2.0的ruby 2.1.5项目以及其他宝石我正在使用rails admin。 I run into several weird problems trying to set this up. 我试图设置这个问题时遇到了几个奇怪的问题。 For instance if I added the is_impressionable call within one of my models for some reason the execution of that file stopped there and I started getting weird errors like any method declared below the is_impressionable failed with undefined error. 例如,如果我在我的一个模型中添加了is_impressionable调用,由于某种原因,该文件的执行在那里停止,我开始得到奇怪的错误,就像在is_impressionable下面声明的任何方法失败并且未定义错误一样。 So what I end up doing was: 所以我最终做的是:

class MyModel < ActiveRecord::Base
  include Impressionist::IsImpressionable
  is_impressionable
end

So this solved my issue and now i can access @my_model_instance.impression_count as expected. 所以这解决了我的问题,现在我可以按预期访问@my_model_instance.impression_count

我在初始化程序'Klass'.constantize Klass每次出现都更改为'Klass'.constantize

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM