I am trying to use the mongodb with ruby on rails
whenever i try to create the new project with
rails new exRuby
preference will be set to sqlite3 in /exRuby/config/database.yml file And automatically "gem 'sqlite3' added to Gem file
But I am trying to use the mongodb with my project. and mongodb is already installed in my system
How to change the database storage to mongodb from sqlite3
Like 'mu is too short' stated, you need to decide which MongoDB interface / gem you want to use to connect to MongoDB. Here is a guide on how to setup a ruby app using Mongoid.
You can run the command rails g mongoid:config to generate the mongoid.yml file. But this is if you choose to use Mongoid. Look at the other gems available and see which one you prefer. Here is a list of available options (according to the MongoDB docs).
Related
I'm trying to create a Rails 5 API with admin views using mongodb and devise for auth. I know the process can go a lot smoother if everything is set up correctly from the beginning. What sort of terminal commands would I need to run to specify to rails what to leave out and what to add in?
i.e. rails new myapp --no-activerecord --db=mongodb --with-devise
There's one tutorial online but its Rails 3 from 2012.
As per the description mentioned in the post, please follow the below mentioned points:
Create a new project using below mentioned command
rails new name_of_the_project --skip-active-record
name_of_the_project = specify the name which you want to keep
--skip-active-record = this will skip loading active-record as an ORM.
Then you need to add mongoid to the gemfile, so that rails can know you want to use it as an ORM
gem 'mongoid', '~> 6.2.0'
After adding , then run following command
bundle install
rails g mongoid:config
The last command configures, mongoid such as generating mongoid.yml.
Hope this answers your question.
I have previously used apartment on Heroku, but now for a client, I am evaluating if it can be used on AWS. Is there a tutorial that shows how to use the apartment gem on Amazon AWS?
After reading https://aws.amazon.com/running_databases/ , I am not sure how to setup my database.
Should I install postgres on my instance or should I use RDS? Does the RDS allow creating multiple schemas if I use Postgres.
Thanks.
Apartment isn't tied to any hosting provider. It just uses Postgres (by default) for its db. Heroku vs AWS/RDS won't matter.
Sure, you can use RDS. Best to just try it out-- setup a new RDS instance with the aws console then plug the connection string into your rails database.yml config and then run your migrations (rake db:migrate) or load your schema (rake db:schema:load).
I'm learning ruby on rails by reading the "agile web development with rails" book. I installed ruby and rails using rvm. I'm using the default sqlite3 database, and generating models and tables is awesome.
I'd like to manually browse my db, just to see the structure.
So at the command line is run
sqlite3
and in the shell
.tables
nothing shows up... Where are my tables?
you want to run
rails dbconsole
or
rails db
as it will load your database etc.
For added clarity, the reason ".tables" returned nothing is because you didn't load the database. Start sqlite3 this way:
sqlite3 pathToDatabase/databaseFileName
I have installed two different version of rails in same gem set. When I do gem list rails it will show as follows:
**rails (3.0.11, 2.3.8)** // This means I have two rails
When I create new rails application it will take latest one, that means app should be created using rails new app_name not using rails app_name.
But I want to use rails 2.3.8 instead of 3.0.11. I know that using RVM helps in switching between different version of rails but they are installed in different gem set. Is there any possibility to switch between different rails version in same gem set?
Thank you.
The later version has higher precedence. You have to be explicit when create app by:
rails _3.0.11_ new my_app
OR
rails _2.3.8_ my_app
I'm assuming you are not using Bundler if you are trying to use 2.3.8, so check your config/enrvironment.rb file and change the RAILS_GEM_VERSION to '2.3.8'
I'm really new at Ruby on Rails development. I'm reading Head First Rails and it says that Rails uses SQLite3 as its database system.
How exactly would I go about uploading my website/application so the world can use it?
Rails uses sqlite3 by default, though you can edit your database.yml file to use a different adaptor (mysql, postgres, etc.) if you'd like. It's not recommended to deploy to production using sqlite3 as your database due to performance issues, though small apps would be ok.