apotonick/cells — Issue #111: Missing template error when using Rails 3.2 via FastCGI
Author: mikesager
Created: 2012-03-07 03:24:39+00:00
State: open

I just upgraded a Rails 3.0 app which was using Cells 3.6.7 to Rails 3.2 with Cells 3.8.2. I am deploying the app on a shared server which requires the use of FastCGI rather than Passenger. When running it, though, from dispatch.fcgi (located in RAILS_ROOT/public), the app errors out when using render_cell in my view. It errors out with the following message (I've substituted RAILS_ROOT for the actual path):

ActionView::Template::Error (Missing template sidebar/show with {:locale=>[:en], :handlers=>[:haml, :erb, :builder], :formats=>[:html, :text, :js, :css, :ics, :csv, :png, :jpeg, :gif, :bmp, :tiff, :mpeg, :xml, :rss, :atom, :yaml, :multipart_form, :url_encoded_form, :json, :pdf, :zip]}. Searched in:
* "/RAILS_ROOT/public/app/cells"

The important part is where it adds "public/" before the "app/cells". After a full day of learning the internals of Cells and ActionPack, I've figured out the issue. In lib/cell/base.rb, DEFAULT_VIEW_PATHS is set to "app/cells". When setup_view_paths! calls 'self.view_paths = self::DEFAULT_VIEW_PATHS', Rails turns the path from a relative path ("app/cells") to an absolute path. Unfortunately, since it is being called from dispatch.fcgi which is found in the public/ subdirectory of the rails app, it includes that in the view path, making it impossible for it to find the cell views.

I used to be able to solve this problem using an initializer which set Cell::Base.view_paths to Rails.root.join('app', 'cells'), but that apparently doesn't have any effect this time around. The only solution I have found this time is to hard code the absolute path to my app in DEFAULT_VIEW_PATHS in lib/cell/base.rb. The fact that this works leads me to suspect that Rails 3.2 ignores any changes to Cell::Base.view_paths after the initial load when it calls setup_view_paths!.

Any thoughts on a more elegant solution than running my own separate branch of Cells with a hardcoded DEFAULT_VIEW_PATHS? :-)