Welcome Guest | Login

too many redirects

I got my site angonoka.org up and running last night, but today various browsers give something like:

Redirect Loop

   

Firefox has detected that the server is redirecting the request for this address in a way that will never complete.

Is this my code or the server? I'm guessing it could be in the routes.rb but I can't figure out why it worked last night and not today.

Ross

2008-08-21 02:24 PM

I have checked the issue and it seems to be related with your code. I ran the dispatch.fcgi file manually from command line and got the following logs.

=
./dispatch.fcgi
Content-Type: text/html; charset=utf-8
Set-Cookie: _depot_session_id=BAh... path=/
Status: 302 Found
Location: http://:/admin/login
X-Runtime: 0.00926
Cache-Control: no-cache
Content-Length: 86

<html><body>You are being <a href="http://:/admin/login">redirected</a>.</body></html>
=

Have you set any redirections in your code..If so it isn't set properly as the location field indicates the following.
=
Location: http://:/admin/login
=

2008-08-21 03:20 PM

Regards,
Rahul
Hi Rahul:

I'm using the code right out of "Agile Development ..." 3rd edition for rails 2.1 to handle the login function for my site. Looking at admin_controller.rb there is a redirect:
###
class AdminController < ApplicationController
 def login
   session[:user_id] = nil
   if request.post?
     user = User.authenticate(params[:name], params[:password])
     if user
       session[:user_id] = user.id
       redirect_to(:action => "index")
     else
       flash.now[:notice] = "Invalid user/password combination"
     end
   end
 end
###
but this seems to me to be correct(?)
Thanks for your attention,
Ross  

2008-08-21 03:46 PM

Can you paste in your routes.rb file and .htaccess?

2008-08-21 08:36 PM

Here they are:

####angonok@angonoka.org [~/bcc8live/config]# cat routes.rb
ActionController::Routing::Routes.draw do |map|
 # The priority is based upon order of creation: first created -> highest priority.

 # Sample of regular route:
 #   map.connect 'products/:id', :controller => 'catalog', :action => 'view'
 # Keep in mind you can assign values other than :controller and :action

 # Sample of named route:
 #   map.purchase 'products/:id/purchase', :controller => 'catalog', :action => 'purchase'
 # This route can be invoked with purchase_url(:id => product.id)

 # Sample resource route (maps HTTP verbs to controller actions automatically):
 #   map.resources :products

 # Sample resource route with options:
 #   map.resources :products, :member => { :short => :get, :toggle => :post }, :collection => { :sold => :get }

 # Sample resource route with sub-resources:
 #   map.resources :products, :has_many => [ :comments, :sales ], :has_one => :seller
 
 # Sample resource route with more complex sub-resources
 #   map.resources :products do |products|
 #     products.resources :comments
 #     products.resources :sales, :collection => { :recent => :get }
 #   end

 # Sample resource route within a namespace:
 #   map.namespace :admin do |admin|
 #     # Directs /admin/products/* to Admin::ProductsController (app/controllers/admin/products_controller.rb)
 #     admin.resources :products
 #   end

 # You can have the root of your site routed with map.root -- just remember to delete public/index.html.
 # map.root :controller => "welcome"

 map.resources :admin

 map.resources :users

 map.resources :photos

 map.resources :medicals

 map.resources :behaviors

 map.resources :shell_heights

 map.resources :carapace_lengths

 map.resources :weights

 map.resources :id_notes

 map.resources :specimens  

 map.resources :catalog

 map.root :controller => "admin"

#  map.connect '', :controller => "specimens"

 # See how all your routes lay out with "rake routes"

 # Install the default routes as the lowest priority.
 map.connect ':controller/:action/:id'
 map.connect ':controller/:action/:id.:format'
end
####angonok@angonoka.org [~/bcc8live/config]#


####angonok@angonoka.org [~/bcc8live/public]# cat .htaccess
# General Apache options
# AddHandler fastcgi-script .fcgi
AddHandler cgi-script .cgi
Options +FollowSymLinks +ExecCGI

# If you don't want Rails to look in certain directories,
# use the following rewrite rules so that Apache won't rewrite certain requests
#
# Example:
#   RewriteCond %{REQUEST_URI} ^/notrails.*
#   RewriteRule .* - [L]

# Redirect all requests not available on the filesystem to Rails
# By default the cgi dispatcher is used which is very slow
#
# For better performance replace the dispatcher with the fastcgi one
#
# Example:
#   RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
RewriteEngine On

# If your Rails application is accessed via an Alias directive,
# then you MUST also set the RewriteBase in this htaccess file.
#
# Example:
#   Alias /myrailsapp /path/to/myrailsapp/public
#   RewriteBase /myrailsapp

RewriteRule ^$ index.html [QSA]
RewriteRule ^([^.]+)$ $1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]

# In case Rails experiences terminal errors
# Instead of displaying this message you can supply a file here which will be rendered instead
#
# Example:
#   ErrorDocument 500 /500.html

ErrorDocument 500 "<h2>Application error</h2>Rails application failed to start properly"
####angonok@angonoka.org [~/bcc8live/public]#

Searching the net I find some references to skip_before_filter as a way of dealing with this problem. I'll try that out and let you know if anything works.

Thanks for taking a look at this.

Ross

2008-08-21 11:32 PM

I tried various permutations of skip_before_filter to no avail. Then on a hunch I took out the following line in routes.rb

#  map.resources :admin

since I thought it might be duplicative of:

 map.root :controller => "admin"

Now the site appears to work. But I'm left with the impression that routes in rails are a black box with mysterious behavior. However, that is always the case with a JCL.

Any insights would be appreciated.

Ross

2008-08-22 12:58 AM

Hi Ark,

By default the controller specified in the map.root will look for the index action. Since there is no index action specified in controller admin the browser has thrown a "Redirect Loop" error.

I have included the login action to the map.root variable given in the config/routes.rb file and also uncommented the line "map.resources :admin". Now your application is loading fine,  please verify it from your end.

Ps: The order in which the rules specified in the routes.rb file has importance. So the map.root should be always placed above the map.resource.



 

2008-08-22 09:20 AM

Hi:

Unfortunately I now get "page not found errors" when I use button_to to go from, say, the catalog page to the home page. This functionality was working last night after I made the change listed above.

I have been through Chapter 20 in the new pdf edition of the Agile book but am not convinced I understand the intricacies of routes yet.

Ross

2008-08-22 01:31 PM

Commenting out the following line in routes.rb:

#  map.resources :admin

as I did before appears to work. I'll keep testing the site and let you know how it is going.

Ross

2008-08-22 02:45 PM


Hello Guest! In order to post you must be an active client with us, please log in or sign up.