How do we use MongoDB in Ruby on Rails? - ruby-on-rails

Does anybody know how to create a rails application that use noSql database?
We do rails new app_name -d mysql for using mysql database, I need to know what command I should fire in case of noSql database.how to configure and connect to that database and how to use table from it. I need reference link to study. Can anybody help me out?
Thanks.

As far as I am concerned you will have to create a new Rails project excluding active record:
rails new my_app --skip-active-record
then you can follow the configuration steps from Mongoid:
http://mongoid.org/en/mongoid/docs/installation.html

http://www.mongodb.org/display/DOCS/Rails+3+-+Getting+Started should get you started.

Related

Access to database tables location created with migrate in Rails

I did a homework on Rails using RubyMine.
I need to submit the homework with the database tables . But I can't access database tables file location, because I don't know under the which folder I created with migrate. I have migrated tables at the rubymine terminal
I used postgresql for database.
I will be so happy if you could help me. Thank you from now.
There is a schema.rb file that represents your database under db/ folder. So this is the answer for your first question.
The answer to second question is in order to deploy your code on a different computer, the third-party softwares need to be installed. In your scenario, this third-party is postgres as db server. To deploy your code, just type on your terminal rake db:setup. This command will create your database, run migrations and finally seed your database if db/seed.rb contains something. As a result, after rails s there should be some output.
It is worth to note that Rails is db agnostic framework. If you did not use postgres specific features then you would use mysql or sqlite on different computers/servers. But keep in mind that you should change the adapter from config/database.yml if you want to use another database.
Ödev sunumunda başarılar.

Ruby on rails Database setup using scaffold generator or Manually

I am new user to ruby on rails. I have some question please give the answer as early as possible
What is the Best way to Create a Database For Your Projects in Rails?
1.Scaffold generator
2.Manually Design Database​
After installing the Rails then create a project using rails new project_name then cd project_name then run rake db:create it will create a database.
You can modify database name like by default rails uses a database e.g name_development or name_production you can modify this on go to project/config/database.yml.
The rails new project_name command creates default database adapter e.g sqlite3 you can define this which adapter he use by default while rails project create.
The sqlite is a development database you should change database adapter while going to production like postgresql or mysql or mongodb...
If you need to use mysql by default then run below command
rails new project_name -d mysql
If you need to use postgresql by default then run below command
rails new project_name -d postgres
It will create a database adapter by default which you need.
Note: You can use both for a command like rake new project_name or rails new project_name
You need to the read the Rails Guides carefully for understand basic Rails. This tutorial assumes you have basic Rails knowledge.
Also here are the Rails Commands
Ruby on rails Database setup using scaffold generator or Manually
The scaffold works after create a database.
You can see the active record basics and for basic association you can see the Michael Hartley tutorial this is good tutorial for new RoR programmer.
After all you need to design manually using reference or defining by index foreign key
First of all decide what kind of database are you going to use. (Msql2 or Postgres are mostly used)
Then design the schema on a paper or anywhere else.
And whenever you're sure. Now everything comes down to 2 different things.
You want things to be created automatically. for example: Views, CRUD for database operations in controllers.
You want to control things on your own. Now create model from rails commands, write associations, and begin writing your code and define routes as well.
NOTE: Point 2 is implemented when you're going to create a custom application and you may need operations other than basic crud.
Now, you can tell us. What actually you want to achieve and people will help you.

rails 4 app with 2 databases: MySQL and Cassandra - where to begin?

Hi have an existing rails 4 app which is using a MySQL database.
I now need to add code that creates dynamically a new table for every object and its attributes.
I decided to use a No SQL solution for this. Initially I wanted to use Mongo DB since I was familair with this. However, my company supports only Cassandra/redis/solr. So I have to pick one of these.
I chose Cassandra but Im not finding any tutorials or examples on how to use it with an existing rails app with a MySQL DB.
I found this ORM for rails-Cassandra but no idea how to make it work with an existing Active record - mysql system.
Any ideas would be very appreciated.
Apologize this post has no code. But I couldnt find any answers for this issue on SO so please excuse if any mistakes.
thanks
ActiveRecord and Cequel will be independent.
As shown in their docs you extend a model's functionality by including the Cequel::Record module.
include Cequel::Record
In order to use it in rails you (obviously) need to add the proper gem in your Gemfile
gem 'cequel'
and create the configuration for the project
bundle exec rake cequel:keyspace:create
After that, you will have a config/cequel.yml from where you will define your settings (as you did in config/database.yml for your MySQL)
MySQL models will still use the ActiveRecord
class Foo < ActiveRecord::Base
...
end
while Cassandra ones will use the Cequel
class Bar
include Cequel::Record
...
end

Beginner Ruby on Rails: Migrating an existing psql database

So basically I am making a new sample application that will run using an external Postgres database and a model, both created by another programmer who has given me this project.
I am supposed to create a rails app that will implement the model and database in order to add some mapping functionality. The problem is that I truly do not know how to migrate an existing database using the "db_name.sqldump" file they provided me. I have installed psql, created a new rails app and added the "pg" gem, but I haven't been able to create a table with all the model information.
I am not sure if I am being clear but I truly am pretty much lost here with RoR. Any input would help.
Assuming you've a pg_dump file, import it from the command line using either of psql or pg_restore.
http://www.postgresql.org/docs/current/interactive/app-pgrestore.html
Follow this railscast by Ryan Bates - http://railscasts.com/episodes/342-migrating-to-postgresql
To convert your sqldump to a sqlite db, Follow these guides : -
script to convert mysql dump sql file into format that can be imported into sqlite3 db
http://code-n-fold.com/2011/11/28/convert-mysql-dump-to-sqlite-format/

Rails Sunspot Solr data source

Thank you in advance for bearing with me. I am new to Solr and looking to integrate into Rails. Although Postgres can text search, Solr seems to be faster..
I understand the modifications that need to happen to the models and controllers within the Rails app itself, however, I cannot seem to grasp when the xml files themselves will be defined and/or stored. Is there a configuration which points to a data source/xml file within Rails that I am missing? I understand that Solr runs and is launched right from the Sunspot gem, but how does that data source (in my case, xml files) communicate with the app? I am not sure if I understand how localhost:8983/solr is to interact with Rails as is would normally.
Any and all help is appreciated, many many thanks. I am running lion 10.7, ruby 1.9.7, rails 3.2.9, the sunspot gem... THANK YOU!
Not sure if I'm answering all of your questions, but when you run the command:
rails generate sunspot_rails:install
it generates a file in the config directory called sunspot.yml. In that file, it specifies how to connect with a running SOLR database depending on your environment.
The Sunspot gem then looks at that file in order to know how to connect to SOLR.

Resources