Rails didn't create any db directory - ruby-on-rails

While I'm creating a new rails app, there is no db directory while skipping active record for using mongodb later, By this command.
rails new app-name --skip-active-record
where rails new app-name created db as expected. And so, rake db:create or rake db:migrate don't act expectedly. I need to edit /db/seeds.rb & i cann't find it.
I tried some post fixing, nothing brings the missing directory. I'm new in rails. Have I missed something? Thanks for cooperating.

By including --skip-active-record in the new command, you are telling Rails to not generate the database files, which is correct if you want to use MongoDB!
Next, you need to remove the sqlite gem from your gemfile and add the MongoDb gem to the gem file. Here is the Ruby Gems page for MongoDB, just copy the gemfile reference from there and paste it into your gemfile. You always need to run the bundle command after altering your gemfile
Then you run rails g mongoid:config and rails will generate the config/mongoid.yml for you.
Here is an article for reference: https://gorails.com/guides/setting-up-rails-4-with-mongodb-and-mongoid

MongoDB does not have a schema so you don't need migrations. Thats kind of the whole point of a schema-less database.
db/seeds.rb is just a plain Ruby file thats executed when you run rake db:seed*. You can create it by running $ touch db/seeds.rb.
There is nothing magical about it.
If you are using Mongoid then everything you need is generated when you run:
$ rails g mongoid:config
So just relax.

Related

accessing Rails Console after deploy to server

I´m having trouble to access the rails console in production.
I used Capistranoto deploy the app to a VPS
If I cd to deploy#myapp:~/myapp/current$and run bundle exec rails cthere I always get the option list for creating new rails project, like rails new
I've also tried bundle exec rails console --productionand rails consoleetc all with the same outcome.
the thing is I must be able to access the console because I have to create an admin user for active admin
might be worth adding that I'm using Passenger/Capistrano and Nginx on Ubuntu 16
Does anyone know what is going on here? Am I doing something wrong?
*EDIT
After running RAILS_ENV=production bundle exec rails c I get this message
Looks like your app's ./bin/rails is a stub that was generated by Bundler.
In Rails 4, your app's bin/ directory contains executables that are versioned
like any other source code, rather than stubs that are generated on demand.
Here's how to upgrade:
bundle config --delete bin # Turn off Bundler's stub generator
rake rails:update:bin # Use the new Rails 4 executables
git add bin # Add bin/ to source control
You may need to remove bin/ from your .gitignore as well.
When you install a gem whose executable you want to use in your app,
generate it and add it to source control:
bundle binstubs some-gem-name
git add bin/new-executable
Loading production environment (Rails 4.2.5)
irb(main):001:0>
You are missing executable files of bin folder in Production after Capistrano deployment.
You need to remove bin from set :linked_dirs from your Capistrano deploy.rb in order to avoid symlinking it.
You can again try cap production deploy, it would take all the executable files from bin to Production.
Now, you can access the rails console using:
RAILS_ENV=production bundle exec rails c
If you are using Capistrano 3, you can include the rails:console option which will allow you to do this from your local machine to gain access to the console on the remote host:
bundle exec cap production rails:console
https://rubygems.org/gems/capistrano-rails-console
The Rails project is deployed in /deploy/your_project_name/current on the server by default. So, you can access it via SSH or ... and run bundle exec rails c to access the Rails console. It works for me!
check if rvm and regarding gemset is suitable for the app
rvm gemset list
rvm list
and then do
bin/rails rails c -e production

Rails project can't connect to postgresql

I was trying to create a rails project with postgresql
I use this
>>rails new ReadingList --database=postgresql
>>rails s
However, it shows this error
Then, I jump to psql and create readinglist_development by myself, but it still show the same error.
In Rails practice, run rake db:create to create the database after creating new Rails project.
I believe the name of the database(readinglist_development) is not matching the database name of ReadingList_development as in database.yml which Rails does not recognize the database created using psql.
Its better not to create databases form db workbenches, better to use rails db commands.

rails rake creates no models

I am deploying a heroku app.
I'm running ubuntu 14.04LTS
After git cloning, I copied the migrate files from my previous project and ran:
bin/rake db:create db:migrate
Everything seemed to be going well until I checked the models folder.
why does rake not create models? How do I fix this?
There is a typo here: it is db:migrate (instead of bd:migrate). Also, rake does not create models.
To create models along with migrations, use rails generate model MyModel.
On the other hand, if all your tables are created using migrations, then just create the model files manually in the app/models folder.

Generate rails db migrations files from active database

Is there any way to take a running database and generate a migration file from it? If not does anyone have any advice on how to approach that?
Background: Have a new project where a PHP developer jumped into a rails project and starting adding tables and columns though PostGres admin tool.
Created a directory called "log" then ran this command
RAILS_ENV=production rake db:schema:dump

Seeding database from engine root fails to locate db/seeds.rb

After creating a new Rails 3.1 gem plugin via:
rails plugin new core --full
I am trying to seed the database with:
rake db:seed
I am running into the following error:
rake aborted!
can't convert nil into String
Moving the seeds.rb file into the test/dummy/db directory seems to resolve the problem. Is there any way to let the db:seed task know what the current working directory is, or where to find the seeds.rb file? The ideal solution would be to keep seeds.rb within my engines db directory
I got this error when I made a mistake naming my seed file "seed.rb", not "seeds.rb". Hope, this helps.
Try creating your engine as
rails plugin new core --full --mountable
You should now be able to do rake db:migrate from your engine root. If it's not a mountable engine, since the generators would typically deploy to your app (in this case test/dummy or spec/dummy) it makes sense that the rake task would be run from the host application.
I solved this by creating a seeds.rb in my dummy/db directory. In the seeds.rb file I created, I just added:
require File.expand_path('../../../../db/seeds.rb', __FILE__)
This basically extends and runs the seeds.rb file in the engines db directory.
Please Note
I am using both --full and --mountable and rake db:seed did not work (plus various other things)
I am using rspec for my tests, so my dummy is in the spec/dummy directory of the engine
I modified my rake and rails so that I could get rspec working
useful posts I have found
rails 3.1 engines with rspec
Hope this helps

Resources