gpt4 book ai didi

ruby-on-rails - 液体 view_paths 错误

转载 作者:太空宇宙 更新时间:2023-11-03 16:58:25 27 4
gpt4 key购买 nike

我正在尝试部署我的 RoR 应用程序。当 RAILS_ENV 设置为开发时,它似乎在我的开发机器上运行良好。但是,当我将它放在生产服务器上并将其设置为生产模式时,导航到起始页后出现以下错误:

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

这是我的 Controller 代码,显示我没有对名为模板的实例变量做任何事情:

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

最佳答案

不要使用@template。使用这个(虽然性能可能很糟糕......你可能需要稍后优化它):

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

render :text => final

关于ruby-on-rails - 液体 view_paths 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3443876/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com