14

I am using Rails 3.2.3 / Ruby 1.9.3p125 / jbuilder (0.4.0)

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.

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"
):

When I check on my server if the jbuilder gem is installed with bundle show jbuilder everything seems right.

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?

Edit: 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?

Here some more Information:

Gemfile

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'

Controller

  def show

  end

show.json.jbuilder - file

 json.(@map, :id)
HaNdTriX
  • 28,732
  • 11
  • 78
  • 85

3 Answers3

7

Your jbuilder seems to be skipped.

Is jbuilder in your Gemfile.lock file?

cat Gemfile.lock | grep jbuilder

If it's missing:

RAILS_ENV=production bundle update 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

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

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!

Do you get the same results with RABL master?

gem 'rabl', :git => "git://github.com/nesquena/rabl.git" 
joelparkerhenderson
  • 34,808
  • 19
  • 98
  • 119
  • Everything works fine on my local mashine. It is also in the gemfile.log. Thanks for you Debugging tip! – HaNdTriX May 25 '12 at 13:04
  • Do these same debugging tips all work on your production server? – joelparkerhenderson May 27 '12 at 00:51
  • Debugging tips all work fine for me, I also have the same problem.There seems to be something 'blocking' these template engines – jamesc Jun 06 '12 at 10:48
  • @jamesw if your project is on github or open source, I'm happy to take a look and see if I can help – joelparkerhenderson Jun 06 '12 at 21:13
  • @joelparkerhenderson - Thank's for the offer. I'm pretty sure this is a server configuration issue (nginx/unicorn) rather than a coding issue. I'm using as_json for now. Due to the sensitivity of app I'm unable to let you in to my private repository or my server. I have had some correspondence with Nathan (owner of Rabl gem), but nothing concrete has come out of that yet. I'll post back here if I ever find the solution. I'd be interested to know if you have the time to set up a test if it is an issue with nginx/unicorn - something I should try myself given a little spare time. – jamesc Jun 06 '12 at 21:24
  • @jamesw Added more debugging tips for you... see if any help. – joelparkerhenderson Jun 07 '12 at 04:01
  • @joelparkerhenderson I have the same problem here, using rabl. Seems that the problems is with the nginx+unicorn combo... – Alex Takitani Jul 12 '12 at 19:42
  • My fix happened to be in the controller. I had to change: "format.json { render json: @records }" to "format.json" and the index.json.jbuilder file I had in place started getting used. – Jon Oct 03 '13 at 00:54
4

The problem is with the load order when rails boots in production. It's needs to be fixed in jbuilder, but here is a workaround:

Gemfile:

gem :jbuilder, :require=>false

config/initializers/jbuilder.rb:

require 'jbuilder'
Sam Oliver
  • 1,194
  • 8
  • 9
0

If you happen to be using grape-jbuilder then their suggestion to add to configu.ru may be causing your problem.

If you are using Rails and grape-jbuilder, then make sure you first require the Rails environment prior to including grape-jbuilder.

config.ru

require ::File.expand_path('../config/environment', __FILE__)

require 'grape/jbuilder'

use Rack::Config do |env|
  env['api.tilt.root'] = 'app/views/api'
end

run Rails.application
Community
  • 1
  • 1
Darren Hicks
  • 4,946
  • 1
  • 32
  • 35