Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

clean up posting

  • Loading branch information...
commit 83b327b8ad864d6264fcdd9e3ed47c6fa03d4142 1 parent 36d616b
@namelessjon authored
Showing with 22 additions and 4 deletions.
  1. +22 −4 address.rb
View
26 address.rb
@@ -60,12 +60,30 @@ def clean_params(param_set=params)
end
post '/:page' do |page|
+ throw :halt, [400, "Need a person in there to hold addresses"] unless params['person'] and Hash === params['person']
# clean up the params
- params.delete_if { |k,v| !%w|person|.include?(k) }
- params['person'] and params['person'].delete_if { |k,v| !%w|name page numbers emails addresses|.include?(k) }
+ params.delete_if { |k,v| "person" != k }
+ params['person'].delete_if { |k,v| !%w|name numbers emails addresses|.include?(k) }
+ params['person']['page'] = page
clean_params
+ @person = addresses.find_one({:page => page}, :fields => [:_id]) || {}
+ @person.merge!(params['person'])
- p params
- redirect "/#{page}/edit"
+ addresses.save(@person)
+ redirect "/#{page}"
+end
+
+post '/' do
+ throw :halt, [400, "Need a person in there to hold addresses"] unless params['person'] and Hash === params['person']
+ # clean up the params
+ params.delete_if { |k,v| "person" != k }
+ 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.merge!(params['person'])
+
+ addresses.save(@person)
+ redirect "/#{person['page']}"
end
Please sign in to comment.
Something went wrong with that request. Please try again.