Skip to content

Loading…

Compatible with Mongoid #34

Closed
hyperrjas opened this Issue · 12 comments

4 participants

@hyperrjas

Hello is this gem compatible with Mongoid?

I have try install this gem with mongoid but not works for me :(

Thank you!

@tute

Shouldn't be hard to add, I don't know yet the differences with mongo_mapper (already working) to really tell though.

@hyperrjas

What is the process for works with Mongomapper? Where can I fin the information for works with Mongomapper and Mongoid?

Thank you?

@tute

Didn't update the README yet cause I'm not sure it's finished, but the steps are almost the same, only changes:

rails g install --orm mongo_mapper
# Then, in config/initializers/impression.rb
config.orm = :mongo_mapper

That should work.

@hyperrjas
@hyperrjas

I get the next error:

ubuntu@ubuntu:~/Desktop/project$ rails g install --orm mongo_mapper
/home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/impressionist-1.1.1/lib/impressionist/models/active_record/impression.rb:1:in   `<top (required)>': uninitialized constant ActiveRecord (NameError)
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/impressionist-1.1.1/lib/impressionist/engine.rb:9:in `block in <class:Engine>'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `instance_exec'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/initializable.rb:30:in `run'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/initializable.rb:55:in `block in run_initializers'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `each'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/initializable.rb:54:in `run_initializers'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/application.rb:96:in `initialize!'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/railtie/configurable.rb:30:in `method_missing'
from /home/ubuntu/Desktop/project/config/environment.rb:5:in `<top (required)>'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/application.rb:83:in `require_environment!'
from /home/ubuntu/.rvm/gems/ruby-1.9.2-p290/gems/railties-3.1.3/lib/rails/commands.rb:22:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'

I have not mongomapper, I have mongoid so if can you add mongoid I would be very gratefull :D.

Thank you!

@tute

Oh, sorry, I made a mistake, the line should be rails g impressionist --orm mongo_mapper.

I'm not sure yet the differences between mongoid and mongo_mapper, so I won't be able to add the support yet.

Regards.

@hyperrjas

Hi guys some notice for mongoid? Thank you very much!

@andeepak

Mongoid support please!!!!

@hyperrjas

After generate the file for mongoid:

rails g impressionist --orm mongo_id
      invoke  mongo_id
      create  config/initializers/impression.rb

This is my mongoid impression.rb file:

class Impression
  include Mongoid::Document
  include Mongoid::Timestamps::Created
  field :impressionable_type, :type => String
  field :impressionable_id, :type => String
  field :user_id, :type => String
  field :controller_name, :type => String
  field :action_name, :type => String
  field :view_name, :type => String
  field :request_hash, :type => String
  field :ip_address, :type => String
  field :session_hash, :type => String
  field :message, :type => String
  field :referrer, :type => String
end

I try run the server and I get this error:

uninitialized constant Impressionist::Engine::MongoId (NameError)
from /home/ubuntu/.rvm/gems/ruby-1.9.3-p125@rails32/gems/impressionist-1.1.1/lib/impressionist/engine.rb:11:in `block in <class:Engine>'

In engine.rb file I have:

require "impressionist"
require "rails"

module Impressionist
  class Engine < Rails::Engine
    initializer 'impressionist.model' do |app|
      require "#{root}/app/models/impressionist/impressionable.rb"
      if Impressionist.orm == :mongo_id
        require "impressionist/models/mongo_id/impression.rb"
        require "impressionist/models/mongo_id/impressionist/impressionable.rb"
        MongoId::Document.plugin Impressionist::Impressionable
      end
    end

    initializer 'impressionist.controller' do
      ActiveSupport.on_load(:action_controller) do
        include ImpressionistController::InstanceMethods
         extend ImpressionistController::ClassMethods
      end
    end
  end
 end

The line 11 is MongoId::Document.plugin Impressionist::Impressionable

How can I fix this error? Thank you!

@hyperrjas

I have removed MongoId::Document.plugin and now the server it does works fine.

The problem is when I add to my model the is_impressionable

 class my_model
   include Mongoid::Document
   include Mongoid::Timestamps::Created
   is_impressionable
 end

undefined local variable or method `is_impressionable' for Microfunc:Class

How can I fix this error?

Thank you!

@jgwmaxwell

Have a look at my pull request #46 - that should sort you out :)

@hyperrjas

Thank you very much @jgwmaxwell excellent, it's fantastic. It does works fine for me your commit :D. Kind Regards!

@hyperrjas hyperrjas closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.