473,320 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

working under webrick but not under passenger

8
Hi!

I have just added login feature to my rails application by following the
instructions from "Agile Web Development with Rails" but now I am getting
strange error (looks to me like some kind of routing problem) under the
passenger/apache. It is working fine under webrick.

The error is:
500 Internal Server Error
The server encountered an internal error or misconfiguration and was
unable to complete your request.

From the log:

SQL (0.3ms) SET SQL_AUTO_IS_NULL=0

Processing ****Controller#index (for 192.168.1.101 at 2010-04-26
18:56:24) [GET]
User Columns (1.7ms) SHOW FIELDS FROM `users`
User Load (0.7ms) SELECT * FROM `users` WHERE
(`users`.`id` IS NULL) LIMIT 1
Redirected to https://******/login/login_page
Filter chain halted as [:authorize] rendered_or_redirected.
Completed in 31ms (DB: 3) | 302 Found [https://******/]

Does anybody have any suggestion what I could do to fix this?

--------------------------------------------
class LoginController < ApplicationController

def add_user
@user = User.new(params[:user])
if request.post? and @user.save
flash.now[:notice] = "User #{@user.name} created"
@user = User.new
end
end

def login_page
session[:user_id] = nil
if request.post?
user = User.authenticate(params[:name], params[:password])
if user
session[:user_id] = user.id
session[:user_name] = user.name
uri = session[:original_uri]
session[:original_uri] = nil
redirect_to(uri || { :action => "index" })
else
flash[:notice] = "Invalid user/password combination"
end
end
end

def logout
session[:user_id] = nil
flash[:notice] = "Logged out"
redirect_to(:action => "login_page")
end

def index
end

def delete_user
if request.post?
user = User.find(params[:id])
if User.count == 1
flash[:notice] = "You can't remove last remaining user!"
else
user.destroy
end
end
redirect_to(:action => :list_users)
end

def list_users
@all_users = User.find(:all)
end
end
------------------------------------------

class ApplicationController < ActionController::Base
before_filter :authorize, :except => :login_page
helper :all # include all helpers, all the time
protect_from_forgery # See ActionController::RequestForgeryProtection
for details
def create_default_variables(ctrl_name)
session[:ctrl_name] = ctrl_name
end
# Scrub sensitive parameters from your log
# filter_parameter_logging :password
private
def authorize
unless User.find_by_id(session[:user_id])
session[:original_uri] = request.request_uri
flash[:notice] = "Please log in"
redirect_to(:controller => "login", :action => "login_page")
end
end
end
------------------------------------------------
require 'digest/sha1'

class User < ActiveRecord::Base
validates_presence_of :name
validates_uniqueness_of :name
attr_accessor :password_confirmation
validates_confirmation_of :password

def validate
errors.add_to_base("Missing password") if hashed_password.blank?
end

def self.authenticate(name, password)
user = self.find_by_name(name)
if user
expected_password = encrypted_password(password, user.salt)
if user.hashed_password != expected_password
user = nil
end
end
user
end

# 'password' is a virtual attribute
def password
@password
end
def password=(pwd)
@password = pwd
create_new_salt
self.hashed_password = User.encrypted_password(self.password,
self.salt)
end

def after_destroy
if User.count.zero?
raise "Can't delete last user"
end
end

private
def self.encrypted_password(password, salt)
string_to_hash = password + "wibble" + salt # 'wibble' makes it
harder to guess
Digest::SHA1.hexdigest(string_to_hash)
end

def create_new_salt
self.salt = self.object_id.to_s + rand.to_s
end
end
-----------------------------------------
login_page.html.erb

<div class="user-form">
<fieldset>
<legend>Please Log In</legend>
<% form_tag do %>
<p>
<label for="name">Name:</label>
<%= text_field_tag :name, params[:name] %>
</p>
<p>
<label for="password">Password:</label>
<%= password_field_tag :password, params[:password] %>
</p>
<p><%= submit_tag "Login" %></p>
<% end %>
</fieldset>
</div>
-------------------------------------------
routes.rb

ActionController::Routing::Routes.draw do |map|

map.resources :controller1
map.resources :controller2
...

map.root :controller => "controller1"

map.connect ':controller/:action/:id'
map.connect ':controller/:action/:id.:format'
end

-------------------------------------------
and apache log:

[error] [client 192.168.1.101] Request exceeded the limit of 10 internal
redirects due to probable configuration error. Use
'LimitInternalRecursion' to increase the limit if necessary. Use
'LogLevel debug' to get a backtrace.

"LogLevel debug" didn't produce any more information.

Update:


It is definitely routing problem.
I could partially solve the problem by adding this:

map.connect 'login', :controller => 'login', :action => "login_page"
map.connect 'login/list_users', :controller => "login", :action => "list_users"
map.connect 'login/add_user', :controller => "login", :action => "add_user"
map.connect 'login/logout', :controller => "login", :action => "logout"

to the routes.rb and just first line is working.
So redirecting to the <app>/login or typing it directly gives login_page action from the login controller.
The remaining problem is that I still can't use any action directly like /login/list_users or even login/login_page.
Apr 29 '10 #1
12 3120
improvcornartist
303 Expert 100+
Have you checked your session variables after login to make sure they are saving accurately? If they aren't, it could be redirecting you back and forth between the original uri and login.
Apr 29 '10 #2
nesko
8
Thanks for the reply! :)
Could you please be more specific about where I should check session variables.
And why doesn't this problem appear with explicit map.connect routes like
map.connect 'login', :controller => 'login', :action => "login_page"
I've checked for instance with:
map.add_user 'add_user', :controller => "login", :action => "add_user"
with
<%= link_to 'Add user', add_user_path %>
This is working with get but not with post.
Apr 29 '10 #3
improvcornartist
303 Expert 100+
I would check within login_page.
Expand|Select|Wrap|Line Numbers
  1. def login_page
  2.   session[:user_id] = nil
  3.   if request.post?
  4.     user = User.authenticate(params[:name], params[:password])
  5.     if user
  6.       session[:user_id] = user.id
  7.       session[:user_name] = user.name
  8.       uri = session[:original_uri]
  9.       session[:original_uri] = nil
  10.       # check here to see what is saved in session variables
  11.       redirect_to(uri || { :action => "index" })
  12.     else
  13.       flash[:notice] = "Invalid user/password combination"
  14.     end
  15.   end
  16. end
I'm not really sure why the problem doesn't appear with explicit map.connect routes.
Apr 29 '10 #4
nesko
8
The problem is that I (the application) will never even come so far (to the login_page) if I try to use full path:
<app>/login/login_page
Just 500 Internal Server Error is shown.
So the problem appears before any session variable is checked/used and therefor I don't see any point in checking session variables.
What I could conclude is that there is clear routing problem because for instance
map.connect 'login/add_user', :controller => "login", :action => "add_user"
is never triggered or recognized.
I have checked routes with
rts = ActionController::Routing::Routes
logger.info(rts.routes)
and this is the related part:

ANY /login/ {:controller=>"login", :action=>"login_page"}
ANY /login/list_users/ {:controller=>"login", :action=>"list_users"}
ANY /login/add_user/ {:controller=>"login", :action=>"add_user"}
ANY /login/logout/ {:controller=>"login", :action=>"logout"}
but anyhow only first one is working.
Apr 29 '10 #5
nesko
8
By the way I'm using session variables in the rest of the application (mostly for the layout/menu things) and those are working fine.
Apr 29 '10 #6
improvcornartist
303 Expert 100+
Is the line map.root :controller => "controller1" still in your routes file? If so, does it behave as you think it should? When you try to go to login/add_user, you get the redirect error?
Apr 29 '10 #7
nesko
8
Yes it is and it is redirecting to the login_page ... well with this routing in place:

map.connect 'login', :controller => 'login', :action => "login_page"

The problem here is that I'm running in test environment and have never got so far to make a proper user I can use to log in (though flash is showing right message so post back is working).
What I tried was to exclude add_user from before_filter but then I get 500 error when posting back. add_user action is never triggered I guess because my logger comands are not writing anything in the log.

So post back is trying the /login/add_user path even if it is called by /add_user and routed by

map.add_user 'add_user', :controller => "login", :action => "add_user"
Apr 29 '10 #8
nesko
8
Update:

Sorry, I have just moved this
map.connect 'login/add_user', :controller => "login", :action => "add_user"
below
map.add_user 'add_user', :controller => "login", :action => "add_user"
and now add user is working and I can log in.
After that the rest of the application is working too.
Even redirect back and forth (to login when not logged in and back to the originated url) is working.

Thank you for the assistance because you gave me the idea how to circumvent the problem. I will be able to live with it using map.<action> shortcuts for the non scaffolding paths.
Though the problem remains and I would appreciate if you and/or other people can help me solve it completely.
Apr 29 '10 #9
improvcornartist
303 Expert 100+
Sorry to keep asking questions. I'm not sure how to debug this one. When you go to add_user, are you passing any params? Does your log show any error details or backtrace?
Apr 29 '10 #10
nesko
8
No problem, I'm really pleased that you are asking questions. Just continue :)

Did you read my last post because it makes your first question a bit obsolete (with reordering routing rules I was able to add user and log in).

Now some more details how the error is manifested:

If I use direct path like /login/add_user I don't get anything in rails log - not a single row though I have config.log_level = :debug in environment.rb
The only thing I get is the same apache error log message:

[error] [client 192.168.1.101] Request exceeded the limit of 10 internal
redirects due to probable configuration error. Use
'LimitInternalRecursion' to increase the limit if necessary. Use
'LogLevel debug' to get a backtrace.

That is why I feel so powerless. There is nothing to go on.
I have also posted this on 3 more rails forums but you are the only person (thank you :) ) that gave any response/comment.
Apr 29 '10 #11
improvcornartist
303 Expert 100+
No, I did not see your last post. I must have been writing a response when you posted it. And you are right, it is very hard to debug when it doesn't give you any details. Sounds like there is still something in the routing or redirects that it doesn't like, but I don't see what it would be. Sorry I can't be of more help there.
Apr 29 '10 #12
nesko
8
Thank you for all your help.

I have also got this list_users.html.erb:
Expand|Select|Wrap|Line Numbers
  1. <h2>Administrators</h2>
  2. <ul>
  3.     <% for user in @all_users %>
  4.         <li><%= link_to "[X]", { # link_to options
  5.                      :controller => 'login',
  6.                      :action => 'delete_user',
  7.                      :id => user
  8.                     },
  9.                     { # html options
  10.                     :method => :post,
  11.                     :confirm => "Really delete #{user.name}?"
  12.                 } %>
  13.             <%= h(user.name) %>
  14.         </li>
  15.     <% end %>
  16. </ul>
to work together with this route:
Expand|Select|Wrap|Line Numbers
  1. map.delete_user 'delete_user', :controller => "login", :action => "delete_user"
it is producing links that are in this form:
Expand|Select|Wrap|Line Numbers
  1. http://<app>/delete_user?id=1
and routing is working.
In some strange way passenger recognize available routes and adapt the link_to to match them. Some light in the darkness at last :)
Apr 29 '10 #13

Sign in to post your reply or Sign up for a free account.

Similar topics

6
by: Mullin Yu | last post by:
hi, i have a web service that has file operations on Windows OS, and there may be a file concurrency issue if only one working directory e.g. c:\working therefore, i want to have a unique sub...
5
by: Martin Heuckeroth | last post by:
Hi We are working on a webservice application and are having some problems with the cookies and/or sessions. We have them working on our intranet but then its not working on the internet. We...
5
by: tshad | last post by:
I have been working with setting my drop boxes to allow double clicking to select an item. It worked fine until I made some changes. I then stripped the page down to the bare essentials to find...
8
by: jojobar | last post by:
Okay, I am trying to do is to test the webresource in 2.0 1. I created a new project with assembly name (and default assembly name) "Office". 2. I added the following to the AssemblyInfo.cs...
2
by: Don | last post by:
I'm having problems with intellisense, autocomplete, etc. suddenly not working in certain classes of a project I'm working on. All the options are set, and it all works fine for most classes, but...
9
by: MSDNAndi | last post by:
Hi, I have a set of simple webservices calls that worked fine using .NET Framework 1.0. I am calling a Java/Apache based webservices, the calling side is not able to supply a proper WSDL. ...
4
by: qbproger | last post by:
I'm developing a plugin for some software. The previous version of the software didn't require a start in directory to be set. This allowed me to leave the working directory to the default in the...
3
by: Jason Huang | last post by:
Hi, In our C# Windows Form application, we are using the SQL Server 2000 as the database server. The Database table MyTable has a field RegistrationDate which represents the Date a client comes...
0
by: WORKING IN FAITH | last post by:
three years I LOVE You Monica More options 1 message - Collapse all WORKING IN FAITH View profile More options Nov 13, 11:29 am three years I LOVE You Monica
3
by: lds | last post by:
On our server we have both applications that have been migrated to use v2.0 of the framework as well as apps that have not yet been migrated and still use 1.1. When I tried to deploy my v2.0 app...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.