views:

61

answers:

2

I'm trying to deploy my RoR app. It seems to be working fine on my development machine when RAILS_ENV is set to development. However, when I put it on the production server and set it into production mode I get the following error after navigating to the start page:

=> Booting Mongrel
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server


Processing PagesController#show (for 173.79.8.203 at 2010-08-09 20:17:21) [GET]
  Parameters: {"slug"=>[], "action"=>"show", "controller"=>"pages"}

NoMethodError (undefined method `view_paths' for #<Liquid::Template:0x7fc6f8b5f8a8>):




Processing ApplicationController#show (for 173.79.8.203 at 2010-08-09 20:17:21) [GET]
  Parameters: {"slug"=>[], "action"=>"show", "controller"=>"pages"}

NoMethodError (undefined method `view_paths' for #<Liquid::Template:0x7fc6f8b5f8a8>):


Rendering /home/flavorpulse/sites/public.flavorpulse.com/public/500.html (500 Internal Server Error)

The weird part is that in my development environment I do get a similar output but I don't get redirected to 500.html. The similar output on my dev machine is:

=> Booting Mongrel
=> Rails 2.3.8 application starting on http://0.0.0.0:3000
=> Call with -d to detach
=> Ctrl-C to shutdown server
  SQL (0.1ms)   SET NAMES 'utf8'
  SQL (0.1ms)   SET SQL_AUTO_IS_NULL=0


Processing PagesController#show (for 127.0.0.1 at 2010-08-09 16:07:50) [GET]
  Parameters: {"slug"=>[], "action"=>"show", "controller"=>"pages"}
  Domain Columns (1.4ms)   SHOW FIELDS FROM `domains`
  Domain Load (45.8ms)   SELECT * FROM `domains` WHERE (`domains`.`domain_name` = 'localhost') LIMIT 1
  Account Columns (1.6ms)   SHOW FIELDS FROM `accounts`
  Account Load (0.8ms)   SELECT * FROM `accounts` WHERE (`accounts`.`id` = 1) 
  CACHE (0.0ms)   SELECT * FROM `accounts` WHERE (`accounts`.`id` = 1) 
  Theme Columns (2.0ms)   SHOW FIELDS FROM `themes`
  Theme Load (0.8ms)   SELECT * FROM `themes` WHERE (`themes`.`id` = 1) 
  PageTemplate Columns (1.4ms)   SHOW FIELDS FROM `page_templates`
  PageTemplate Load (0.3ms)   SELECT * FROM `page_templates` WHERE (`page_templates`.`name` = 'index') AND (`page_templates`.theme_id = 1) LIMIT 1
  CACHE (0.0ms)   SELECT * FROM `domains` WHERE (`domains`.`domain_name` = 'localhost') LIMIT 1
  CACHE (0.0ms)   SELECT * FROM `accounts` WHERE (`accounts`.`id` = 1) 
  CACHE (0.0ms)   SELECT * FROM `accounts` WHERE (`accounts`.`id` = 1) 
  CACHE (0.0ms)   SELECT * FROM `themes` WHERE (`themes`.`id` = 1) 
  PageLayout Load (0.4ms)   SELECT * FROM `page_layouts` WHERE (`page_layouts`.theme_id = 1) LIMIT 1
  PageLayout Columns (1.4ms)   SHOW FIELDS FROM `page_layouts`
  CACHE (0.0ms)   SELECT * FROM `domains` WHERE (`domains`.`domain_name` = 'localhost') LIMIT 1
  CACHE (0.0ms)   SELECT * FROM `accounts` WHERE (`accounts`.`id` = 1) 
  CACHE (0.0ms)   SELECT * FROM `accounts` WHERE (`accounts`.`id` = 1) 
  Page Load (0.3ms)   SELECT * FROM `pages` WHERE (`pages`.`show_in_navigation` = 1) AND (`pages`.account_id = 1) 

NoMethodError (undefined method `view_paths' for #<Liquid::Template:0x10337ef98>):


Rendering rescues/layout (internal_server_error)

But you can see the major difference is that on the production server it doesn't look like any calls are being made to the database.

Updated 2010/08/09 @ 17:41 EST:

Here's my controller code which shows I'm not doing anything with an instance variable named template:

class PagesController < ApplicationController
  def show
    if params[:slug].blank?
      # show homepage
      page = current_account.theme.page_templates.find_by_name("index")
    else
      # show the right page
      #TODO: This doesn't support slashes in the slug. This URL will make this barf: about/us/us/us/us/about-us.html
      page = Page.first(:conditions => ["account_id = :account_id AND slug = :slug", { :account_id =>  current_account.id, :slug => params[:slug] }])
    end

    if page.nil?
      #TODO: Render a better 404 page.
      content = "4oh4 - File Not Found"
    else
      content = page.content      
    end

    assigns = {
    }
    render_page(content, assigns)
  end
end
A: 

What you are seeing is just how Rails is configured to behave differently between Development and Production environments. Main differences for you are:

  • Default production log level doesn't show database accesses although they are almost certainly happening
  • In production you get redirected to a 500 notice. In development you often see a stack trace,

The error you are encountering is present in both cases. Don't assume that just because it appears to be less serious in development that it's not still a problem.

A similar issue was posted here. Maybe this is your problem.

bjg
I had seen that posting but I am not setting an instance variable (or any variable named template at any scope level). I've updated the question to show my controller code.
Corith Malin
A: 

don't use @template. Use this (performance may suck though ... you may have to optimize that later):

final_render = Liquid::Template.parse(page_layout)  # Parses and compiles the template
final = final_render.render(assigns)

render :text => final
Kyle West