Rails 3.2 issue, rabl is not in the handlers list #157

Closed
simonc opened this Issue Jan 27, 2012 · 28 comments

9 participants

@simonc

Hi,

I updated my app to Rails 3.2.1 and when I use the app in my browser everything is fine.
When it comes to use it in the cmd line I get an error telling me that the template is not found.

Missing template prospects/create, application/create with {:locale=>[:fr], :formats=>[:json], :handlers=>[:erb, :builder, :arb, :coffee, :slim]}

My app uses Active Admin and in the cmd line I use an auth_token to connect. I checked that the template is present:

$ ll app/views/prospects/create.json.rabl 
-rw-r--r-- 1 simonc staff 82 jan 26 17:00 app/views/prospects/create.json.rabl

Any idea where it could come from ?
Thanks

@simonc

I tried this in the create action:

respond_to do |format|
  ...
  format.json { render text: Tilt.mappings.inspect }
end

It returns the list with rabl listed in it :/

..., "slim"=>[Slim::Template], "rabl"=>[RablTemplate]}

It's very weird...

@simonc

I got this in the Rails console:

ActionView::Template::Handlers.extensions #=> [:erb, :builder, :arb, :coffee, :slim]
@nesquena
Owner

Interesting, I think we need to take a look at registering RABL in Rails 3.1.X and Rails 3.2.X. Hopefully I can get around to that soon or someone can send me a pull request.

@nesquena
Owner

Here's where template registering takes place:

https://github.com/nesquena/rabl/blob/master/lib/rabl/template.rb

Also why is Tilt installed there in your Rails app? Is Rails using Tilt?

@simonc

Tilt is required by sass-rails, slim, sinatra and sprockets. Here is a sample of my Gemfile.lock:

...
sass-rails (3.2.4)
  railties (~> 3.2.0)
  sass (>= 3.1.10)
  tilt (~> 1.3)
...
sinatra (1.3.2)
  rack (~> 1.3, >= 1.3.6)
  rack-protection (~> 1.2)
  tilt (~> 1.3, >= 1.3.3)
...
slim (1.1.0)
  temple (~> 0.3.5)
  tilt (~> 1.3.2)
...
sprockets (2.1.2)
  hike (~> 1.2)
  rack (~> 1.0)
  tilt (~> 1.1, != 1.3.0)
...
tilt (1.3.3)
...
@simonc

Sinatra is just here for a part of the app, the app is using Rails 3.2.1. It was working with Rails 3.1.3 previously.

@nesquena
Owner

I see thanks for the explanation. I suspect the issue is just proper registration of template handlers on 3.2: https://github.com/nesquena/rabl/blob/master/lib/rabl/template.rb#L44 That template works well for Rails 3 which is where I tested it. If you have any thoughts about how to add an additional handler that is 3.2 compatible, I'd appreciate it. Either way, I hope to make things 3.2 compatible soon.

@simonc

I don't know if you can apply the same pattern but slim is still working with Rails 3.2.
They do it here https://github.com/stonean/slim/blob/master/lib/slim/template.rb
Hope it helps :)

@simonc

Ok, I digged a bit in the Rails handlers code. I found this in actionpack/lib/action_view/template/handlers.rb

def self.extensions
  @@template_extensions ||= @@template_handlers.keys
end

This code is supposed to return the list of handlers extensions. The funny thing is that when I change it to this:

def self.extensions
  @@template_handlers.keys
end

Suddenly calling the list returns a good value:

ActionView::Template::Handlers.extensions #=> [:erb, :builder, :arb, :coffee, :rabl, :slim]

I don't know if it can be considered as a Rails bug.

I saw that in fact Slim was using Temple to register, I don't know if this is an option for Rabl.

@nesquena
Owner

@simonc Thanks for digging in, that is rather interesting that it actually does show up but somehow the cached value doesn't reflect it. Perhaps it is being added too late? I'd rather avoid adding temple as a dependency. I will investigate how other templaters register in 3.2 and hopefully we can fix this soon by tweaking template registration.

@cmccorvey

Any update on this issue? I'd like to move to Rails 3.2 but this is a non-starter.

@nesquena
Owner

If anybody has any ideas on why Rails 3.2 is not registering the handler properly, I'd appreciate it... https://github.com/nesquena/rabl/blob/master/lib/rabl/template.rb

@cmccorvey

I noticed on the latest 3.2.2 branch there has been a change to ActionView::Template::Handlers

old:
def register_template_handler(extension, klass)
@@template_handlers[extension.to_sym] = klass
end

new:
def register_template_handler(extension, klass)
@@template_handlers[extension.to_sym] = klass
@@template_extensions = nil
end

When I added code in by application.rb to redefine that method it seems to work just fine. The issue I have though is that the same old code seems to be in 3.1 and 3.0 branches, but perhaps my eyes (and the number of hours I've recently put in staring at code) fooled me.

Anyway, I seem to have a work-around and it appears Rails 3.2.2 will fix the issue.

Can someone else validate this? By the way, I am using the following Ruby version on OS X Lion:
ruby 1.9.3p125 (2012-02-16 revision 34643) [x86_64-darwin11.3.0]

@nesquena
Owner

Fascinating, thanks for the update, great news that Rails 3.2.2 might fix this, otherwise if there's anything I can do differently to work around this, I'd love to know.

@cmer

+1

@cmccorvey

Oh, just one more tidbit: rails/rails#5101

@nesquena
Owner

Yep that looks like it should fix the issue, thanks for attaching that request. Look forward to being able to mark the Rails 3.2 issue as resolved. Can someone confirm on Rails 3.2.2 that rabl works as expected?

@tolsen

While rabl is now in the handlers list, Rails 3.2.2 appears to have otherwise made things worse. See #180

@cmer

Has this bug been addressed? Waiting for this to upgrade to Rails 3.2.2. Thanks!

@databyte
Collaborator

This is fixed in Rails 3.2.2 in terms of finding the right template handler.

In issue 180, @carhartl 's comment and my comment addresses the issue of changing content types when you attempt to render a RABL partial in the middle of an existing HTML template. Otherwise rendering a RABL file directly render file: 'show.json.rabl' works just fine. (though it should be render 'show', formats: :json or just render 'show')

@nesquena
Owner

@databyte I don't use Rails 3.2.2 and I haven't tested RABL on it. Is this sufficiently resolved that I should close this ticket?

@databyte
Collaborator

I have a 3.1.4 and 3.2.2 branch of the site I'm working on and I have the latest RABL working on both now.

The only outstanding issue is rendering RABL within another HTML or JS template which is covered in issue 180 and should be fixed in 3.2.3 when that releases.

@nesquena
Owner

I actually don't think this is a rabl error anymore. I am going to close this issue. Rails 3.2 seems to work fine with RABL with fixes mentioned in the other tickets. Otherwise, the handler issues are fixed in Rails 3.2.3 finally

@nesquena nesquena closed this Mar 28, 2012
@andrebrujah

This issue is happening to me in Rails 3.2.3.

"Missing template rooms/index, application/index with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :jbuilder, :coffee]}. Searched in ..."

To install RABL i have put "gem 'rabl'" in GemFile, run bundle install command..

My rabl version is: 0.7.2

@andrebrujah

My error sorry.

I hadn't restart the server after install the Gem.

@dcdieci

I still get this error in rails 4.0.3
ActionView::MissingTemplate (Missing template resorts/find, application/find with {:locale=>[:en], :formats=>[:json], :handlers=>[:erb, :builder, :raw, :ruby, :jbuilder, :coffee]}. Searched in:
... app/views"

@jlebrijo

Same for Rails 4.1.1: ActionView::MissingTemplate - Missing template consultants/index, application/index with {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :arb, :haml]}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment