Topic: Development vs. Production (odd problems in production)

Is there a good rundown anywhere (other than the source code) on the differences between production mode and development mode?

I know that production mode caches the code so it doesn't have to reload on every request, but what about other changes? I've been running into some errors in production that didn't appear in development, and it would be nice to do a check for all potential changes at once as I fix them.

Some of the more noticeable issues:

Code like this in a model
[code Ruby]
def authorize_owner(user_id)
  if self.user_id == user_id
    return true
  else
    return false
  end
end
[/code]
works fine in development but always returns false in production.

I'm also using some code like this in my controller for AJAX calls:
[code Ruby]
def get_item_link
  item = Item.find(params[:id])
  unless item.nil?
    render :text => item.link
  else
    render :text => ""
  end
end
 
def get_item_comments
  item = Item.find(params[:id])
  unless item.nil?
    render :text => item.comments
  else
    render :text => ""
  end
end
[/code]
In development, they all work fine, but in production, the second function returns an exception saying that it can't find the template for that action. The first function works fine, though, and neither of them have a template.

Re: Development vs. Production (odd problems in production)

If you want to know the complete list of differences between development and production mode just look in config/environments.  You can customize how development and production mode work by editing the appropriate files there (though there's seldom any need to edit them).

As for your first problem, it might be due to your production database having different information in it than your development one.  I can't tell any more without seeing the full code.

Oh, one more thing to watch out for:  make sure you freeze rails into your vender/rails directory in both your development and production apps.  You can do this by running this command:
rake rails:freeze:edge TAG=rel_1-2-3

Re: Development vs. Production (odd problems in production)

OK, so the only changes that exist are the ones specified in the config/environment files? That's good to know.

The first problem is very strange -- if I have a log line like so:

[code Ruby]
logger.info "Self: #{self.user_id}, Parameter: #{user_id}"
[/code]

It will output "Self: 4, Parameter: 4" but still return false. Very mysterious.

Is there a reason to freeze rails if we're not running on a shared host? I've been good about making sure that both of them are using the most up-to-date gems...

Re: Development vs. Production (odd problems in production)

Whoops, I just realized I posted this in "Installing Rails" as opposed to "Rails Programming." Can a moderator move it? :-)

Re: Development vs. Production (odd problems in production)

Try this:

logger.info "Self: #{self.user_id.class.name}, Parameter: #{user_id.class.name}"

It will tell you what class each one is. Perhaps one is a string while the other is an integer so they aren't comparing properly.

Railscasts - Free Ruby on Rails Screencasts

Re: Development vs. Production (odd problems in production)

Thanks ryan -- not sure why I didn't think of that myself! That was indeed the problem.

Very strange, though, using identical versions of Rails and Ruby on both my local machine and the remote machine, but my local machine shows both of the compared values as Fixnum, whereas the remote machine sees one as Fixnum and one as String.

Easily fixable with a .to_i call, but I wonder if there aren't more subtle issues lurking out there. The remote machine is a 64-bit AMD whereas my local is a 32-bit PPC, but I would hope a super-high-level language like Ruby wouldn't care about such things... and yet that's the only difference between the two environments that I can see.

The first problem seemed to go away on its own, which also makes me a little wary. A closer examination of the codebase might be in order. :-(

Re: Development vs. Production (odd problems in production)

That's strange. If you can, follow the String variable back to where it is created. Where does it originate?

Railscasts - Free Ruby on Rails Screencasts

Re: Development vs. Production (odd problems in production)

A difference between the development environment and the production environment is that the application code is reloaded on each request in the development environment, which slows down response time, but is suited for development as the web server is not required to be restarted between code changes. Another difference is that in development environment error reporting is enabled and caching is turned off while in production mode error reporting is turned off and caching is turned on.

Re: Development vs. Production (odd problems in production)

Ryan,

I think I've tracked it down -- the problem was arising when the user session was created from a cookie instead of a login. My authorization code was just sticking the cookie's user_id (which comes in as a string) into the session instead of the ID of the user it found with the cookie. Does that make sense? These sorts of things are easier to describe at a whiteboard with boxes and arrows. :-)

Since my local machine wasn't using cookies, I was always creating the user from a login and didn't see the problem.

I need to do a little more testing to see, but I'm 90% sure that's the culprit.