Ruby on Rails: reducing complexity of parameters in a RESTFul HTTP POST request (multi-model)
Posted
by randombits
on Stack Overflow
See other posts from Stack Overflow
or by randombits
Published on 2010-05-05T01:16:39Z
Indexed on
2010/05/05
3:18 UTC
Read the original article
Hit count: 326
I'm using cURL to test a RESTFul HTTP web service. The problem is I'm normally submitting a bunch of values normally like this:
curl -d "firstname=bob&lastname=smith&age=25&from=kansas&someothermodelattr=val" -H "Content-Type: application/x-www-form-urlencoded" http://mysite/people.xml -i
The problem with this is my controller will then have code like this:
unless params[:firstname].nil?
end
unless params[:lastname].nil?
end
// FINALLY
@person = People.new(params[:firstname], params[:lastname], params[:age], params[:from])
etc..
What's the best way to simplify this? My Person model has all the validations it needs. Is there a way (assuming the request has multi-model parameters) that I can just do:
@person = People.new(params[:person])
and then the initializer can take care of the rest?
© Stack Overflow or respective owner