RailsCasts Pro episodes are now free!
Learn more or hide this
Resources
Note: if you don't want the long MongoDB IDs in the URL, you can set up any attribute as a permalink
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
config.gem "mongo_mapper"
MongoMapper.database = "todo-#{Rails.env}"
class Project include MongoMapper::Document key :name, String, :required => true key :priority, Integer many :tasks end
class Task include MongoMapper::Document key :project_id, ObjectId key :name, String key :completed, Boolean belongs_to :project end
Project.all Project.all(:order => "name") Project.all(:priority => 3) Project.all(:priority.gte => 2) Project.all(:priority.in => [2, 3])
<p> <%= f.label :priority %><br /> <%= f.select :priority, [1,2,3,4,5] %> </p>
<p> <%= f.label :project_id %><br /> <%= f.collection_select :project_id, Project.all, :id, :name %> </p>