代码之家  ›  专栏  ›  技术社区  ›  Corith Malin

液体视图路径错误

  •  2
  • Corith Malin  · 技术社区  · 14 年前

    => 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)
    

    奇怪的是,在我的开发环境中,我确实得到了类似的输出,但没有重定向到500.html。在我的开发人员机器上类似的输出是:

    => 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)
    

    但是您可以看到主要的区别是,在生产服务器上,似乎没有对数据库进行任何调用。

    更新日期:2010/08/09@17:41 EST:

    下面是我的控制器代码,它显示我没有对名为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
    
    2 回复  |  直到 13 年前
        1
  •  0
  •   Kyle West    14 年前

    不要使用@template。使用这个(性能可能会很差。。。您以后可能需要对此进行优化):

    final_render = Liquid::Template.parse(page_layout)  # Parses and compiles the template
    final = final_render.render(assigns)
    
    render :text => final
    
        2
  •  0
  •   bjg    14 年前

    您所看到的只是Rails如何配置为在开发环境和生产环境之间表现出不同的行为。您的主要区别是:

    您遇到的错误在这两种情况下都存在。不要仅仅因为它在开发中看起来不那么严重就认为它不是一个问题。

    发布了一个类似的问题 here