How to raise a 403 error?

Hello all,

I am working on Rails 3, and I would like to return a forbidden error
message from a controller.

I had trying something like that:

def my_action
  respond_to do |format|
    format.html { redirect_to(login_path, :warning =>
I18n.t('.forbidden'), :status => :forbidden) }
    format.xml { render :xml => I18n.t('.forbidden'), :status =>
:forbidden }
  end
end

But it is not want I need, because I don't want to redirect to a
particular page, such as login. I just want to return a standard 403
error (with raise maybe). Is that possible?

Thank you for your help.

Hello,

I did not check if it was still there in Rails 3, but in rails 2,

ActionController::Base#render accepts a :nothing options used to render empty text :

usage :

render :nothing => true, :status => whatever

And you have a short cut method for “only headers” response ActionController::Base#head

usage :

format.xml { head :forbidden }

Mickael

Mickael Gerard wrote:

render :nothing => true, :status => whatever

And you have a short cut method for "only headers"
response ActionController::Base#head
usage :

format.xml { head :forbidden }

Mickael

You solved my question. Many thanks.