How to return correct HTTP error codes from Ruby on Rails application
http, ruby, ruby-on-rails
Solution
You should render page with correct status.
render(:file => File.join(Rails.root, 'public/403.html'), :status => 403, :layout => false)
Problem
I have RoR 3.0 web application which is acting as an OAuth API provider. Now, in API I'd like to return correct HTTP error codes to the API consumer. How do I do this? Here is example: ``` def destroy_oauth @item = Item.find(params[:id]) if(!@item.nil? && @item.user_id == current_user.id) @item.destroy respond_to do |format| format.js format.xml end else raise ActionController::RoutingError.new('Forbidden') end end ``` So, in case of error I'm trying to return Forbidden 403 code. Still, when running this I'm getting always 404 Not Found returned. How do I return the correct code? Or is this somehow webserver configurable thing?