· 1 min read
Screencast: MongoDB und MongoMapper
Download
Download (24.1 MB, 13:13) Alternativer download für iPod & Apple TV (15.3 MB, 13:13)
Resourcen:
- MongoDB
- Installing MongoDB on OS X
- MongoMapper
- Why I think Mongo is to Databases what Rails was to Frameworks
- Nifty Generators
- Full episode source code
Quellcode:
[bash] rails todo sudo rake gems:install script/generate nifty_layout script/generate nifty_scaffold project name:string —skip-migration script/generate nifty_scaffold task project_id:string name:string completed:boolean —skip-migration [/bash]
[ruby] # config/environment.rb config.gem “mongo_mapper”
# config/initializers/mongo_config.rb MongoMapper.database = “todo-#{Rails.env}”
# models/project.rb class Project include MongoMapper::Document key :name, String, :required => true key :priority, Integer many :tasks end
# models/task.rb class Task include MongoMapper::Document key :project_id, ObjectId key :name, String key :completed, Boolean belongs_to :project end
# script/console Project.all Project.all(:order => “name”) Project.all(:priority => 3) Project.all(:priority.gte => 2) Project.all(:priority.in => [2, 3]) [/ruby]
[html]
<%= f.label :priority %>
<%= f.select :priority, [1,2,3,4,5] %>
<%= f.label :project\_id %>
<%= f.collection\_select :project\_id, Project.all, :id, :name %>