json
if valid_user
render status: :ok, json: { user_id: valid_user.id}
else
render status: :unauthorized, json: {}
end
def destroy
@post.destroy!
head :no_content
end
HTTP Status Code | Symbol |
---|---|
200 | :ok |
201 | :created |
202 | :accepted |
204 | :no_content |
400 | :bad_request |
401 | :unauthorized |
403 | :forbidden |
404 | :not_found |
500 | :internal_server_error |
503 | :service_unavailable |
Views rendering convention
By default, controllers in Rails automatically render views with names that correspond to valid routes.(NOTE: according to valid routes
not action method)
class ThingsController < ApplicationController
end
# routes.rb
get '/ten_best_things_in_your_life' => 'things#ten_best_things_in_your_life', as: :ten_best_things_in_your_life
# /views/things/ten_best_things_in_your_life.html.slim
Visiting /ten_best_things_in_your_life
will render ten_best_things_in_your_life
page correspondingly due to Rails's convention