views:

86

answers:

2

How would I go about accessing the Bundle-Fu plugin from this rake task?

I have tried everything out and nothing seems to work.

Note: assets_javascript & assets_css are both arrays of files that are pulled from a central location to keep this rake task and the view DRY.

desc "Generate cached css/js files" 
task :asset_cache_generate => :environment do
    puts 'Caching Javascript & CSS Files'
    bundle do
        javascript_include_tag assets_javascript
        stylesheet_link_tag assets_css
    end
end

Thanks in advance for your help!

- Tom

+1  A: 

The method bundle is mixed into ActionView so you can only call it from a templace instance.

Unfortunately, you can't neither mix it into a custom class nor use it in a Rake task because it depends on many Rails template helpers/resources (concat, flash...). It would be too hard to reproduce all of them in order to make the method working.

See http://github.com/timcharper/bundle-fu/blob/8056fd05c7ee4f637eb6137d544e91065400daab/lib/bundle_fu.rb

Simone Carletti
A: 

My model class includes a plugin called constant_cache, its used for caching the constants from the table so that they can be directly used in the app.

When i write a rake task, the plugin is not loaded with the model.

#Decode.rb

require 'constant_cache'
class Decode < ActiveRecord::Base
#The key that will be used to retrieve constants is the constant_value
caches_constants :key => :constant_value
end

Rake Task:

require 'active_record/fixtures'

namespace :db do
desc "Seed the database with always/ fixtures."
task :always => :environment do
load_fixtures "seed/always", :always
end
end

filter_params.yml

Filter_Param_1:
id: 1
filter_param: chapter_status
disp_value: Active
internal_param: modul_status
internal_value: <%= Decode::CHAPTER_STATUS_ACTIVE %>
sort_order: 1

I get the following error while running rake task:

The exact error was: NameError: uninitialized constant Decode::CHAPTER_STATUS_ACTIVE

Any ideas?

Thanks, Pratik

Pratik Khadloya
That's a different question, not an answer to the one covered in this thread. You should better post it as a new question ("Ask question" in the top right of the page), more people will see it that way.
sth