Sutto/rocket_pants

Documentation on Post and Put methods

Opened this issue · 4 comments

Hi, love rocket_pants as I am learning APIs. I think a big win for us nubes would be to include Post and Put requests (Create and Update methods) in the docs. Right now its just GET requests and index/show methods.

These examples are lacking here and in the linked sample app.

Thanks!

There's nothing different or fancy about processing requests like that - have you just tried following the samples in:

http://guides.rubyonrails.org/action_controller_overview.html

and

http://guides.rubyonrails.org/active_record_querying.html

Ok cool, those "expose" and "collection" methods were looking kinda special and I wasn't sure if there was a PUT and POST equivalent.

So I'll just do
def create
Post.create(params[:post])
end

etc.

Thanks!

expose/collection are purely to simplify OUTPUT of anything! so you can do:

expose Post.create(params[:post])

which will render out the result of the creation (i.e. the object itself), and if you do Post.create!() it'll render out the validation errors automatically without doing anything else.

kindof like magic, but it's not i promise.

(one more note: whenever you have a question like this, check the source first, expose is a super simple method and really just wraps some stuff around render_json)

See why we should add the examples? :o) Thanks!

~ Adam Braus
608-770-0230

On Friday, September 27, 2013 at 5:19 PM, mbhnyc wrote:

expose/collection are purely to simplify OUTPUT of anything! so you can do:
expose Post.create(params[:post])
which will render out the result of the creation (i.e. the object itself), and if you do Post.create!() it'll render out the validation errors automatically without doing anything else.
kindof like magic, but it's not i promise.


Reply to this email directly or view it on GitHub (#75 (comment)).