http status code 404 - Resource not found errors in Ruby on rails -


i'm new ror, know activerecord::recordnotfound can mapped http 404 error. there other resource in ruby on rails non-existence raise resourcename::resourcenamenotfound ?

also there errors raised ror equivalent 520, 403, 401 ?

any appreciated.

rails should respond proper http error codes in correlation conventions of http protocol. i've worked rails while , haven't seen exceptions. can raise own exceptions this

@record = modelname.find_by(field_name_goes_here: params[:some_parameter_name_goes_here])     if not @record.blank?         render "view_file_name_goes_here"     else         raise activerecord::recordnotfound     end 

this code cause rails respond 404. making request route has not been defined result in 404.

other examples:

a syntax error in code respond 500.

if using devise or other gem authorization, unauthorized request result in rendering 401. there won't in rails render 401 out of box. remember, of requests defined through routes.rb , it's controllers decide response render , if response should return http error code.

this question here provides information on how render types of error codes:

return specific http status code in rails

if looking debug http error code suggest setting rails environment configuration consider requests local requests. display understandable error.

purpose of "consider_all_requests_local" in config/environments/development.rb?


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -