ruby on rails - This controller's create action works fine, but the almost identical update is just returning 204 regardless -


def create     if request.headers['auth'] == user.first.token       @post = post.create(post_params)       @post.save       respond_with(@post)     else       error =   { error:  'gotta authed create' }       respond_with(error, :status => 401, location: nil)     end   end   def update     if false #request.headers['auth'] == user.first.token       @post.update_attributes(post_params)       respond_with(@post)     else       error =   { error:  'gotta authed edit' }       respond_with(error, :status => 401, location: nil)     end   end 

enter image description here

edit:

apparently considered correct way handle put rails team (i have no idea why) can give me insight on how handle respond_with behaving consistently?

see these issue/pullreqs better idea of how rails considers response correct https://github.com/rails/rails/issues/9862 https://github.com/rails/rails/pull/9887

okay, apparently need pass block respond_with if want customize - see https://stackoverflow.com/a/18929275/1429856

my solution change

respond_with(error, :status => 401, location: nil) 

to

  respond_with error |format|     format.json { render json: error, :status => 401, location: nil }   end 

Comments

Popular posts from this blog

commonjs - How to write a typescript definition file for a node module that exports a function? -

openid - Okta: Failed to get authorization code through API call -

ios - Change Storyboard View using Seague -