Start the MongoDB server:
$ brew services start mongodb
Generate Rails scaffolding for houses:
$ rails generate scaffold house name street city state
This creates the following model:
$ cat app/models/house.rb
class House
include Mongoid::Document
field :name, type: String
field :street, type: String
field :city, type: String
field :state, type: String
end
Start the rails server:
$ rails s
Go To:
http://localhost:3000/houses
Click New House
, and fill in the information.
Now we will use mongoDB shell to view our database (name in mongoid.yml
):
$ mongo ra_investor_development
> show collections
houses
> db.houses.find()
{ "_id" : ObjectId("58a44524daba3773cc012681"), "name" : "The White House", "street" : "President Street", "city" : "Washington", "state" : "District of Columbia" }
http://kerrizor.com/blog/2014/04/02/quick-intro-to-mongodb-in-rails