Rails3 ActionView 模板处理程序在生产服务器上不起作用 [英] Rails3 ActionView Template Handlers doesn't work on Production Server
问题描述
我使用的是 Rails 3.2.3/Ruby 1.9.3p125/jbuilder (0.4.0)
I am using Rails 3.2.3 / Ruby 1.9.3p125 / jbuilder (0.4.0)
在我的 view/mycontroller
文件夹中,我有一个 show.json.jbuilder
文件.当我使用 rails s -e production
在本地机器上测试所有内容时,一切正常.JSON 按预期呈现.
In my view/mycontroller
folder i got a show.json.jbuilder
file.
when I test everything on my local machine with rails s -e production
everything works fine.
The JSON gets rendered as espected.
但是当我部署到 Ubuntu LTS (nginx/unicorn) 时,我收到以下错误消息:
But when I deploy to Ubuntu LTS (nginx/unicorn) I get the following Error Message:
ActionView::MissingTemplate (Missing template mycontroller/show, application/show with {:locale=>[:de, :en], :formats=>[:json], :handlers=>[:erb, :builder]}. Searched in:
* "/home/deployer/apps/myapp/releases/#############/app/views"
):
当我在服务器上检查 jbuilder gem 是否与 bundle show jbuilder
一起安装时,一切似乎都正确.
When I check on my server if the jbuilder gem is installed with bundle show jbuilder
everything seems right.
奇怪的是错误消息没有显示 :handlers=>[:erb, :builder, :jbuilder]
显然缺少 jbuilder 处理程序.但是我该如何解决这个问题?
weird is that the Error message does't show :handlers=>[:erb, :builder, :jbuilder]
The jbuilder handler is obviously missing. But how do I solve the problem?
问题不是基于 Jbuilder.我试过 rabl 也出现同样的问题.
The Problem is not based on Jbuilder. I tried rabl and the same problem appears.
有没有人有提示,如何调试?
Does any one has a hint, how to debug this?
这里有更多信息:
宝石文件
source 'https://rubygems.org'
gem 'rails', '3.2.3'
gem 'jquery-rails'
gem 'mysql2'
gem 'simple_form'
# Gems used only for assets and not required
# in production environments by default.
group :assets do
gem 'sass-rails', '~> 3.2.3'
gem 'coffee-rails', '~> 3.2.1'
gem 'uglifier', '>= 1.0.3'
gem 'bootstrap-sass', '2.0.2'
end
# Use unicorn as the app server
gem 'unicorn'
# Deploy with Capistrano
gem 'capistrano'
# for performance monitoring
gem 'newrelic_rpm'
# use asset pipline and flash
gem 'swf_fu', '~> 2.0'
gem 'geocoder'
# To use Jbuilder templates for JSON
gem 'jbuilder'
控制器
def show
end
show.json.jbuilder - 文件
show.json.jbuilder - file
json.(@map, :id)
推荐答案
您的 jbuilder 似乎被跳过了.
Your jbuilder seems to be skipped.
jbuilder 是否在您的 Gemfile.lock 文件中?
Is jbuilder in your Gemfile.lock file?
cat Gemfile.lock | grep jbuilder
如果丢失:
RAILS_ENV=production bundle update jbuilder
jbuilder 可以加载吗?
Is jbuilder loadable?
RAILS_ENV=production bundle exec rails console
> require 'jbuilder'
=> false # this is false if jbuilder is pre-loaded
你能在控制台中构建吗?
Can you build in the console?
> Jbuilder.encode{|j| j.foo :bar }
=> "{\"foo\":\"bar\"}"
你能在你的控制器动作中构建吗?
Can you build in your controller action?
def the_method_you_are_testing
raise Jbuilder.encode{|j| j.foo :bar }
end
您是否在不同的服务器设置中看到相同的错误,例如 Apache &乘客而不是 Nginx &独角兽,还是简单的 Rails 服务器?
Do you see the same error with a different server setup, such as Apache & Passenger instead of Nginx & Unicorn, or simply rails server?
rails server -e production
如果您将服务器应用从生产改为开发,您会得到相同的结果吗?
Do you get the same results if you change your server app from production to development?
rails server -e development
对于 RABL,您可以尝试将 RABL gem 最后 放在您的 Gemfile 中吗?
For RABL, can you try putting the RABL gem last in your Gemfile?
gem 'rails'
#...
gem 'rabl'
在需要构建器后立即尝试注册?
Try registering immediately after requiring builder?
require 'tilt'
require 'rabl'
# ...
require 'builder'
Rabl.register!
使用 RABL master 得到相同的结果吗?
Do you get the same results with RABL master?
gem 'rabl', :git => "git://github.com/nesquena/rabl.git"
这篇关于Rails3 ActionView 模板处理程序在生产服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!