Follow Installation in Rails 3 of Mongo Mapper i add to config/application.rb file :
config.generators do |g|
g.orm :mongo_mapper
end
when rails generate migration my_migration i got :
error mongo_mapper [not found]
but when rails generate model my_model, i got a fine model class with include MongoMapper::Document and this output :
invoke mongo_mapper
create app/models/user.rb
invoke test_unit
create test/unit/user_test.rb
create test/fixtures/users.yml
You don't have migrations while working with MongoDB.
Because MongoDB is a schema less database.
That's the reason you can't generate migrations with mongo mapper.
Related
I'm using rails 5.1.4
devise 4.4.1
factory_bot_rails 4.8.2
rails g devise User
Running via Spring preloader in process 15889
invoke active_record
create db/migrate/20180213152941_devise_create_users.rb
create app/models/user.rb
invoke rspec
create spec/models/user_spec.rb
error factory_bot_rails [not found]
insert app/models/user.rb
route devise_for :users
Thanks for replay, the problem was that in config/application.rb, fixture_replacement need to pass :factory_bot and not factory_bot_rails, reading the doc I see that are distinct gems.
When migrating the database, I made a spelling mistake.
I want to generate a scaffold by running:
rails generate scaffold Micropost context:text user_id:integer
rails db:migrate
Although I made a mistake by leaving out the colon when I ran:
rails generate scaffold Micropost context:text user_id integer
rails db:migrate
I want to undo this migration, how to do it?
(I'm using Rails 5.0.0.1)
When I run rails db:migrate, I get an error of:
SQLite3::SQLException: table "microposts" already exists:
When I run rails db:migrate:status, I get the following output:
Status Migration ID Migration Name
up 20161024021157 Create users
up 20161024025545 ********** NO FILE **********
down 20161024025805 Create microposts
I tried to use rails db:migrate:down VERSION=20161024025805. There wasn't any message showing in the command line. Then I ran rails db:migrate. The error is the same.
rails db:rollback will simply rollback one migration which I believe is what you are looking for
For a more specific rollback, you can run rails db:migrate:down VERSION=numberofversion
Replace the numberofversion with the version number of the migration file generated, for example:
rails db:migrate:down VERSION=1843652238
Edit:
Since you are getting the error that the Microposts table already exists, you must follow these steps to remove the table:
Run rails generate migration DropMicroposts
Go to the /db/migrate folder and find the latest migration file you just created
In that file paste this:
class DropMicroposts < ActiveRecord::Migration
def up
drop_table :microposts
end
end
run rails db:migrate
After this, run rails generate scaffold Micropost context:text user_id:integer
Then run rails db:migrate
In rails 4.2.0/ rspec 3.2.2/ rspec-rails 3.2.1. I'm trying to disable specs being generated when I generate new models. I'm using a spec folder structure that is different than the rails convention and would like to not have delete/move generated spec files for every new model. I tried to add generator configuration as mentioned in the rails guides and in What is the syntax to skip creating tests, assets & helpers when running `rails generate controller`?
My config/application.rb contains this:
config.generators do |g|
g.test_framework :rspec
g.model_specs false
g.view_specs false
g.helper_specs false
g.controller_specs false
g.model_spec false
g.helper_specs false
g.request_specs false
g.feature_specs false
end
and I'm still getting:
$rails g model category
invoke active_record
create db/migrate/20150416174523_create_categories.rb
create app/models/category.rb
invoke rspec
create spec/models/category_spec.rb
invoke factory_girl
create spec/factories/categories.rb
Even if I explicitly add tags:
$rails g model category --no-model-specs
invoke active_record
create db/migrate/20150416174908_create_categories.rb
create app/models/category.rb
invoke rspec
create spec/models/category_spec.rb
invoke factory_girl
create spec/factories/categories.rb
Anyone solved this before?
Simply set test_framework to something falsey if you want to disable all generators:
config.generators do |g|
g.test_framework nil
end
You sadly can't disable model specs from the generators alone. They're not optional.
Using rails 2.3.5 when I tried to run the command : script/generate scaffold user user_name:string email:string, I get the error:
uninitialized constant Rails::Generator::GeneratedAttribute::ActiveRecord
I have searched for this error and I found the only solution is to uncomment this line in my environment.rb
config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
which is already uncommented in my environment. What can I do?
a newbie's fault :) , i came from rails 3 , and i have installed bundle to be able to install gems in my rails 2 project but i wasn't know that i should comment the line above again in case of using bundler as it wasn't mention in the instruction of adding bundler.
after commenting # config.frameworks -= [ :active_record, :active_resource, :action_mailer ]
then i got the following
➜ ~ script/generate scaffold user user_name:string email:string
exists app/models/
exists app/controllers/
exists app/helpers/
exists app/views/users
exists app/views/layouts/
exists test/functional/
exists test/unit/
exists test/unit/helpers/
exists public/stylesheets/
overwrite app/views/users/index.html.erb? (enter "h" for help) [Ynaqdh] y
force app/views/users/index.html.erb
create app/views/users/show.html.erb
create app/views/users/new.html.erb
create app/views/users/edit.html.erb
create app/views/layouts/users.html.erb
create public/stylesheets/scaffold.css
create app/controllers/users_controller.rb
create test/functional/users_controller_test.rb
create app/helpers/users_helper.rb
create test/unit/helpers/users_helper_test.rb
route map.resources :users
dependency model
exists app/models/
exists test/unit/
exists test/fixtures/
create app/models/user.rb
create test/unit/user_test.rb
create test/fixtures/users.yml
create db/migrate
create db/migrate/20130820214343_create_users.rb
and rake db:migrate is done, so that means now everything is fine ?
I'm trying to generate a model called ClassAttendance, but Rails keeps naming the migrations class_attendances. I've tried correcting this problem by placing the following code the following code in \config\initializers\inflections.rb:
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable "attendance"
end
This seems to work fine in the rails console:
$ rails console
Loading development environment (Rails 3.2.6)
irb(main):001:0> "attendance".pluralize
=> "attendance"
Unfortunately, the rails model generator seems to be unaffected:
$ rails generate model ClassAttendance
invoke active_record
create db/migrate/20120806201910_create_class_attendances.rb
create app/models/class_attendance.rb
invoke rspec
create spec/models/class_attendance_spec.rb
Does it have something to do with this?
irb(main):002:0> "class_attendance".pluralize
=> "class_attendances"
Or is there some other problem I'm not seeing?
That is the workaround, you need to place it in the inflections.rb file in the config/initializers/. So your config/initializers/inflections.rb would be
ActiveSupport::Inflector.inflections do |inflect|
inflect.uncountable %w( attendance class_attendance ClassAttendance)
end