trailblazer / cells

View components for Ruby and Rails.
https://trailblazer.to/2.1/docs/cells.html
3.07k stars 236 forks source link

NameError: undefined local variable or method on asset:precompile #303

Closed opti closed 8 years ago

opti commented 9 years ago

I have a concept cell:

app/concepts/checkout/coupon/cell.rb

module Checkout
  module Coupon
    class Cell < Cell::Concept
      property :coupon
      property :number

      def show
        coupon ? render(:current) : render(:new)
      end

      private

      def coupons_path
        checkout_coupons_path(number)
      end
    end
  end
end

View for that cell: app/concepts/checkout/coupon/views/current.erb

<%= link_to '', coupons_path, remote: true, method: :delete %>

This cell is also has a checkout_coupon.js.coffee file in views directory and application.rb has a setting for that cell with asset:

config.cells.with_assets = %w(
  checkout/coupon/cell
)

config.assets.initialize_on_precompile is true by default.

But it fails to precompile assets:

bin/rake assets:precompile RAILS_ENV=development RAILS_GROUPS=assets
@@@@@ ["app/concepts/checkout/coupon/views"]
rake aborted!
NameError: undefined local variable or method `coupons_path' for #<#<Class:0x007fff24bb5fc8>:0x007fff259e3c80>
/app/concepts/checkout/coupon/views/current.erb:1:in `_evaluate_template'
/gems/sprockets-3.2.0/lib/sprockets/erb_processor.rb:26:in `call'
/gems/sprockets-3.2.0/lib/sprockets/erb_processor.rb:13:in `call'
/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:75:in `call_processor'
/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:57:in `block in call_processors'
/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in `reverse_each'
/gems/sprockets-3.2.0/lib/sprockets/processor_utils.rb:56:in `call_processors'
/gems/sprockets-3.2.0/lib/sprockets/loader.rb:86:in `load_asset_by_uri'
/gems/sprockets-3.2.0/lib/sprockets/loader.rb:45:in `block in load'
/gems/sprockets-3.2.0/lib/sprockets/loader.rb:155:in `fetch_asset_from_dependency_cache'
/gems/sprockets-3.2.0/lib/sprockets/loader.rb:38:in `load'
/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:20:in `block in initialize'
/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in `yield'
/gems/sprockets-3.2.0/lib/sprockets/cached_environment.rb:47:in `load'
/gems/sprockets-3.2.0/lib/sprockets/base.rb:63:in `find_asset'
/gems/sprockets-3.2.0/lib/sprockets/base.rb:70:in `find_all_linked_assets'
/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:138:in `block in find'
/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:114:in `block (2 levels) in logical_paths'
/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:223:in `block in stat_tree'
/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:207:in `block in stat_directory'
/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in `each'
/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:204:in `stat_directory'
/gems/sprockets-3.2.0/lib/sprockets/path_utils.rb:222:in `stat_tree'
/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in `each'
/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:105:in `block in logical_paths'
/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in `each'
/gems/sprockets-3.2.0/lib/sprockets/legacy.rb:104:in `logical_paths'
/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:136:in `find'
/gems/sprockets-3.2.0/lib/sprockets/manifest.rb:162:in `compile'
/gems/sprockets-rails-2.3.2/lib/sprockets/rails/task.rb:70:in `block (3 levels) in define'
/gems/sprockets-3.2.0/lib/rake/sprocketstask.rb:147:in `with_logger'
/gems/sprockets-rails-2.3.2/lib/sprockets/rails/task.rb:69:in `block (2 levels) in define'
/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `block in load'
/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:240:in `load_dependency'
/gems/activesupport-4.2.2/lib/active_support/dependencies.rb:268:in `load'
-e:1:in `<main>'
Tasks: TOP => assets:precompile
(See full trace by running task with --trace)
opti commented 9 years ago

any chance on adding assets_path option?

apotonick commented 9 years ago

I thought you wanted to do that???

opti commented 9 years ago

heh, miscommunication

apotonick commented 8 years ago

This is fixed in 4.1.0 with https://github.com/trailblazer/cells-rails.