I'm trying to use mongodb and postgresql simultaneously with Rails
3.1. I believe I have everything set up correctly.

What I'm interested in knowing is how to get rails to flip-flop back-
and-forth between mongoid and activerecord.

For example, if I want to generate an ActiveRecord model after using
mongoid, rails automatically defaults to the Mongoid gem.
rails g model Blogpost
invoke mongoid
create app/models/blogpost.rb
invoke rspec
create spec/models/blogpost_spec.rb

How would I get rails to use ActiveRecord instead, and vice versa?

Thanks in advance

Mike

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Search Discussions

  • Neener54 at Jan 22, 2012 at 5:18 pm
    You could just go into the model and change it's inheritance. I've
    never used mongoid but I think that push comes to shove, simply
    switching << [modeltype] wouldn't be too hard. I'll keep an eye open
    for you though and see if I can figure it out.
    On Jan 21, 7:41 pm, Mike Kim wrote:
    I'm trying to use mongodb and postgresql simultaneously with Rails
    3.1. I believe I have everything set up correctly.

    What I'm interested in knowing is how to get rails to flip-flop back-
    and-forth between mongoid and activerecord.

    For example, if I want to generate an ActiveRecord model after using
    mongoid, rails automatically defaults to the Mongoid gem.
    rails g model Blogpost
    invoke mongoid
    create    app/models/blogpost.rb
    invoke rspec
    create    spec/models/blogpost_spec.rb

    How would I get rails to use ActiveRecord instead, and vice versa?

    Thanks in advance

    Mike
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Mike Kim at Jan 24, 2012 at 6:00 am
    Thanks Neener54, but I think I found the answer.

    Instead of running:
    rails g model Blogpost
    I need to run
    rails g active_record:model Blogpost
    and that should generate all the ActiveRecord files, even though I
    have mongoid installed.

    However, now I am running into issues with migration and trying to use
    the Devise plugin.

    After installing the Devise plugin and auto-generating a User
    ActiveRecord model using:
    rails g active_record:devise User
    I try to run my migrations. Here is the error output:
    rake db:migrate
    rake aborted!
    undefined method `devise' for User(Table doesn't exist):Class

    Tasks: TOP => db:migrate => environment
    (See full trace by running task with --trace)

    I tried the same flow in a separate project, except using only
    ActiveRecord with no Mongoid and I was able to run migrations
    successfully. Apparently, Mongoid is messing up my ActiveRecord
    classes when I try to run rake.

    Would anyone have a solution? For example, is there a similar way to
    force rake to use ActiveRecord, such as when using rails-generate
    (rails g active_record:***)?

    By the way, I'm using ruby 1.9.2p290, Rails 3.1.0, Mongoid 2.3,
    bson_ext 1.4, and devise 1.5.3.

    Thanks in advance

    Mike



    On Jan 22, 12:18 pm, Neener54 wrote:
    You could just go into the model and change it's inheritance.  I've
    never usedmongoidbut I think that push comes to shove, simply
    switching << [modeltype] wouldn't be too hard.  I'll keep an eye open
    for you though and see if I can figure it out.
    On Jan 21, 7:41 pm, Mike Kim wrote:

    I'm trying to use mongodb and postgresql simultaneously with Rails
    3.1. I believe I have everything set up correctly.
    What I'm interested in knowing is how to get rails to flip-flop back-
    and-forth betweenmongoidand activerecord.
    For example, if I want to generate an ActiveRecord model afterusing
    mongoid, rails automatically defaults to theMongoidgem.
    rails g model Blogpost
    invokemongoid
    create    app/models/blogpost.rb
    invoke rspec
    create    spec/models/blogpost_spec.rb
    How would I get rails to use ActiveRecord instead, and vice versa?
    Thanks in advance
    Mike
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
  • Mike Kim at Jan 24, 2012 at 7:12 am
    Okay, I believe this is a bug in Devise.

    When I generate the User model using:
    rails g active_record:devise User
    I get a config/initializers/devise.rb file with the following setting:

    require 'devise/orm/mongoid'

    However, if I run "rails g active_record:devise User", the setting
    should actually be:

    require 'devise/orm/active_record'

    I would expect the mongoid ORM to be used by devise if I ran
    rails g devise user
    without specifying "active_record", but I didn't.

    Unless I'm missing something, this seems like a bug in Devise. I filed
    a bug with the Devise team. Hopefully I'm not wrong and just wasting
    people's time.

    Thanks,

    Mike

    On Jan 23, 10:00 pm, Mike Kim wrote:
    Thanks Neener54, but I think I found the answer.

    Instead of running:
    rails g model Blogpost
    I need to run
    rails g active_record:model Blogpost
    and that should generate all the ActiveRecord files, even though I
    have mongoid installed.

    However, now I am running into issues with migration and trying to use
    the Devise plugin.

    After installing the Devise plugin and auto-generating a User
    ActiveRecord model using:
    rails g active_record:devise User
    I try to run my migrations. Here is the error output:
    rake db:migrate
    rake aborted!
    undefined method `devise' for User(Table doesn't exist):Class

    Tasks: TOP => db:migrate => environment
    (See full trace by running task with --trace)

    I tried the same flow in a separate project, except using only
    ActiveRecord with no Mongoid and I was able to run migrations
    successfully. Apparently, Mongoid is messing up my ActiveRecord
    classes when I try to run rake.

    Would anyone have a solution? For example, is there a similar way to
    force rake to use ActiveRecord, such as when using rails-generate
    (rails g active_record:***)?

    By the way, I'm using ruby 1.9.2p290, Rails 3.1.0, Mongoid 2.3,
    bson_ext 1.4, and devise 1.5.3.

    Thanks in advance

    Mike

    On Jan 22, 12:18 pm, Neener54 wrote:






    You could just go into the model and change it's inheritance.  I've
    never usedmongoidbut I think that push comes to shove, simply
    switching << [modeltype] wouldn't be too hard.  I'll keep an eye open
    for you though and see if I can figure it out.
    On Jan 21, 7:41 pm, Mike Kim wrote:

    I'm trying to use mongodb and postgresql simultaneously with Rails
    3.1. I believe I have everything set up correctly.
    What I'm interested in knowing is how to get rails to flip-flop back-
    and-forth betweenmongoidand activerecord.
    For example, if I want to generate an ActiveRecord model afterusing
    mongoid, rails automatically defaults to theMongoidgem.
    rails g model Blogpost
    invokemongoid
    create    app/models/blogpost.rb
    invoke rspec
    create    spec/models/blogpost_spec.rb
    How would I get rails to use ActiveRecord instead, and vice versa?
    Thanks in advance
    Mike
    --
    You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
    To post to this group, send email to rubyonrails-talk@googlegroups.com.
    To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
    For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
grouprubyonrails-talk @
categoriesrubyonrails
postedJan 22, '12 at 2:42a
activeJan 24, '12 at 7:12a
posts4
users2
websiterubyonrails.org
irc#RubyOnRails

2 users in discussion

Mike Kim: 3 posts Neener54: 1 post

People

Translate

site design / logo © 2022 Grokbase