Skip to content
samstickland edited this page Jul 2, 2015 · 16 revisions

General errors

I get the error: ‘uninitialized constant ShoppingCartCell’ when accessing a page with render_cell call.

Ensure you have put ‘cells’ under ‘app’ directory, and ‘shopping_cart_cell.rb’ in: ‘/app/cells’

I get the error: ‘application.rb:10:in `’: uninitialized constant Cells::Rails::Application (NameError)’ when trying to generate a new cell ‘$ rails generate cell cart show -e haml’.

Don’t name your application (or test/example application) ‘cells’. Instead, name it ‘cell_example’, or something different, etc.
$ rails new cell_example

Rendering problems

Asset paths are wrong

(Rails 3.1) image_tag "logo.png" doesn’t give me `assets/logo.png` but `images/logo.png`.

Make sure to include the correct helper into your cell

include Sprockets::Helpers::RailsHelper

(Rails 4+)
Make sure to include into your cell

include Sprockets::Rails::Helper
self.assets_prefix = Rails.application.config.assets.prefix
self.assets_environment = Rails.application.assets
self.digest_assets = Rails.application.config.assets[:digest]

More information in This Issue

I get `ActionView::Template::Error: Missing host to link to!` when using a *_url helper.

Include the UrlFor module into your cell.


class ShoppingCartCell < Cell::Base
  include ActionController::UrlFor

Using the *_url helpers implies accessing the request instance, which kinda breaks encapsulation. Cells doesn’t support breaking things, that’s why you have to include it manually.

Mongrel errors

Mongrel dies on startup with the error: “undefined method `plugins’ for Rails:Module”

Ensure you are running Rails version 2.2 by checking the line in environment.rb containing: "RAILS_GEM_VERSION = "

Mongrel dies on startup with the error: “/Library/Ruby/Gems/1.8/gems/activesupport-2.2.2/lib/active_support/dependencies.rb:445:in `load_missing_constant’: uninitialized constant Dependencies (NameError)”

Ensure you’re running the latest version of the cells plugin from github.
cd vendor/plugins
git clone git://github.com/apotonick/cells.git

Mongrel dies on startup with the error: “/vendor/plugins/cells/init.rb:42:in `evaluate_init_rb’: undefined method `engines_available?’ for Cell:Module (NoMethodError)”

  1. In environment.rb, ensure the line: “require File.join(File.dirname(FILE), ‘../vendor/plugins/cells/boot’)” is ABOVE the Rails::Initializer line.

How do I…

… prepend a view path for cells like with Rails’ prepend_view_path?

Add this to an initializer:

Cell::Base.prepend_view_path("/Path/to/whatever")

Ensure that autotest picks up changes to your cell files ?

Add this to your autotest/discover.rb file

Autotest.add_hook :initialize do |at|
  at.add_mapping %r%^app/cells/(.*)\.rb$% do |_, m|
    "test/cells/#{m[1]}_test.rb"
  end
  
  at.add_mapping %r%^test/cells/(.*)_test\.rb$% do |filename, _|
    filename
  end
end

… use native helper methods in controller

Use `include` with the following additional steps:


    include ActionView::Helpers::AssetTagHelper

    def star
    image_tag("star-#{@rating}.png", alt:"#{@rating}-Star")
    end

    def controller
      parent_controller
    end

    helper_method :star

You want to use helper inside other helper

You need just include that helper inside helper where you want to user methods


module SidebarHelper
  include PricesHelper
end

Try to avoid it.

I get the error message “NoMethodError (undefined method `dom_class’ for #MyCell:0×00000007e98868)”

You need to add some additional methods to help out form_for


    def dom_class(record, prefix = nil)
      ActionView::RecordIdentifier.dom_class(record, prefix)
    end

    def dom_id(record, prefix = nil)
      ActionView::RecordIdentifier.dom_id(record, prefix)
    end
Clone this wiki locally