Permalink
Browse files

Make the collection used configurable

Also, admit we're dealing primarily with people here, not addresses
  • Loading branch information...
1 parent ef0945e commit 670a1f9dd029d4d4ff0c76feb7beb13cc38f7a4d @namelessjon committed Jul 1, 2010
Showing with 14 additions and 13 deletions.
  1. +10 −9 app.rb
  2. +2 −2 black_book/templates/index.html
  3. +2 −2 black_book/views/index.rb
View
19 app.rb
@@ -16,10 +16,11 @@ class App < ::Sinatra::Base
}
}
set :name, 'BlackBook'
+ set :collection, 'people'
helpers do
- def addresses
- settings.mongo['addresses']
+ def people
+ settings.mongo[settings.collection]
end
def clean_params(param_set=params)
@@ -50,7 +51,7 @@ def clean_params(param_set=params)
end
get '/' do
- @addresses = addresses.find({}, :fields => [:name, :page], :sort => [[:page, :asc]]).to_a
+ @people = people.find({}, :fields => [:name, :page], :sort => [[:page, :asc]]).to_a
mustache :index
end
@@ -60,13 +61,13 @@ def clean_params(param_set=params)
end
get '/:page' do |page|
- @person = addresses.find_one(:page => page)
+ @person = people.find_one(:page => page)
not_found unless @person
mustache :show
end
get '/:page/edit' do |page|
- @person = addresses.find_one(:page => page) || {'page' => page}
+ @person = people.find_one(:page => page) || {'page' => page}
mustache :edit
end
@@ -78,10 +79,10 @@ def clean_params(param_set=params)
params['person']['page'] = page
clean_params
- @person = addresses.find_one({:page => page}, :fields => [:_id]) || {}
+ @person = people.find_one({:page => page}, :fields => [:_id]) || {}
@person.merge!(params['person'])
- addresses.save(@person)
+ people.save(@person)
redirect "/#{page}"
end
@@ -92,10 +93,10 @@ def clean_params(param_set=params)
params['person'].delete_if { |k,v| !%w|name page numbers emails addresses|.include?(k) }
clean_params
- @person = addresses.find_one({:page => person['page']}, :fields => [:_id]) || {}
+ @person = people.find_one({:page => person['page']}, :fields => [:_id]) || {}
@person.merge!(params['person'])
- addresses.save(@person)
+ people.save(@person)
redirect "/#{person['page']}"
end
end
@@ -1,6 +1,6 @@
<h1>{{title}}</h1>
<ul>
- {{#addresses}}
+ {{#people}}
<li><a href='/{{page}}'>{{name}}</a></li>
- {{/addresses}}
+ {{/people}}
</ul>
@@ -3,8 +3,8 @@
module BlackBook
module Views
class Index < Layout
- def addresses
- @addresses
+ def people
+ @people
end
end
end

0 comments on commit 670a1f9

Please sign in to comment.