views:

12

answers:

1

I'm new to Ruby on Rails, so maybe I'm doing something wrong...

In a controller (Users), I have a "before_filter" that calls an "authenticate" method in my ApplicationController class.

The Users controller can be accessed via HTML or XML with

respond_to do |format|
  format.html
  format.xml
end

The problem is when the filter doesn't pass, the authenticate method always shows the HTML page...

I have both files authentication_failed.html.erb and authentication_failed.xml.erb.

In the controller, the "authentication_failed" method looks like this:

def authentication_failed
  respond_to do |format|
    format
    format.xml
  end
end

The authenticate method (the one that gets called by the filter) has this code:

if !(authenticated) then
  redirect_to authentication_failed_path
end

What can I do to have the authentication failed to respond with the XML instead of the HTML page?

A: 

The better is fix the format in redirect_to

if !(authenticated) then
  redirect_to authentication_failed_path(:format => params[:format]
end

Now you keep the same format after your redirection

shingara