Params[:obj] not being set from a form

I have a form that looks like this:

<%= start_form_tag :action => ‘login’ %>

Username: <%= text_field 'user', 'username' %>
Password: <%= password_field 'user', 'password' %>

<%= submit_tag ‘Login’ %>
<%= end_form_tag %>

And in the controller, this:

def login
if request.get?
# If the deleted flag is set in the session, remove it
# now and give the user a new session.
# (when a user logs out, their session is removed too)
reset_session if session[:deleted]
@user = User.new
else
logger.info(“params user is:”)
logger.info(params[:user])
@user = User.new(params[:user])
@authenticated_user = @user.try_to_authenticate

This code was written a long time ago and now I am trying to run it on
the production server. On my development server, everything is fine.
However on the production server (with environment set to ‘development’
for this debugging) it seems that params[:user] is never set.

On the development server I can see usernamepassword
in the log. On the production server, nothing is output. This
obviously causes problems because a user object with no
username/password is not going to authenticate (“can’t convert nil into
String” when trying to hash the users password using Digest::SHA1).

At first I thought it might be the versions of ruby/rails etc, but both
now report this:

About your application’s environment
Ruby version 1.8.5 (i686-linux)
RubyGems version 0.9.0
Rails version 1.2.1
Active Record version 1.15.1
Action Pack version 1.13.1
Action Web Service version 1.2.1
Action Mailer version 1.3.1
Active Support version 1.4.0

What would cause one machine to have a nil params[:user]? The two
machines have exactly the same code.

I had a similar problem. I resolved it by adding this line to the
very top of my User model, before the class declaration:

require “digest/sha1”

If that doesn’t help, I’m wondering what your params object looks
like. What does this statement produce:

logger.info(params.inspect)

– Jeff

Jeff wrote:

I had a similar problem. I resolved it by adding this line to the
very top of my User model, before the class declaration:

require “digest/sha1”

Thanks for the suggestion, I have that inside the actual class. Using
irb I can verify that the require returns ‘true’ and Digest::SHA1(“foo”)
returns a correct hash.

If that doesn’t help, I’m wondering what your params object looks
like. What does this statement produce:

logger.info(params.inspect)

Quite simply… it doesn’t produce anything! There is no output from
params.inspect on the broken host. Something must be wrong, but I
cannot figure out what.

The only major differences are:

  • the production (broken) machine uses HTTPS
  • the production (broken) machine uses SSL certificates for the client

I haven’t changed anything in rails to reflect the above two things, but
POST requests do go to the right place if watching the logs.

David wrote:

Jeff wrote:

logger.info(params.inspect)

Quite simply… it doesn’t produce anything! There is no output from
params.inspect on the broken host. Something must be wrong, but I
cannot figure out what.

The only major differences are:

  • the production (broken) machine uses HTTPS

This one seems to be what causes the problems. I’m using Apache and
after disabling SSL the application works as expected.

So I suppose my question now is why isn’t params[…] filled properly if
using an HTTPS connection?