On Tuesday, September 18, 2012 12:28:00 PM UTC-4, gsw wrote:
>
> # I have not tested this- just a possibility of something that would use
> roar-rails which provides consume! and deserialization.
> def create
> # another method to implement that relies on proper authorization
> if can_create?
> respond_with(errors: ['Access denied to create #{self.class.name}'],
> status: forbidden)
> end
> begin
> @company = Company.new(params[:company])
> consume! @company
> if @company.errors
> respond_with(errors: [@company.errors], location: users_url,
> status: unprocessable_entity)
> else
> respond_with(@company, location: users_url, status: created)
> end
> rescue
> puts $!.inspect, $@
> # TODO: add support for other formats
> respond_to do |format|
> format.json { render json: {errors: [$!.message]}, status:
> (:internal_server_error) }
> end
> end
> end
>
Ok, this was pretty wrong. Got off on the wrong foot by looking at this and
underestimating respond_with:
http://apidock.com/rails/ActionController/MimeResponds/respond_with
It's better documented here:
http://blog.plataformatec.com.br/2009/08/embracing-rest-with-mind-body-and-soul/
And the docs are getting better between rails 3 and 4:
rails 3:
https://github.com/rails/rails/blob/3-2-rel/actionpack/lib/action_controller/metal/mime_responds.rb
master/rails 4:
https://github.com/rails/rails/blob/master/actionpack/lib/action_controller/metal/mime_responds.rb
In the process, I started writing this (don't ask- pretty lame but maybe it
will continue):
https://github.com/garysweaver/convenient-actionpack
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/lEJqMHz2nd0J.
For more options, visit https://groups.google.com/groups/opt_out.