I have created a rake task and I need to require a gem and two source files. I've used the bundle install to install the gem so that's not a problem, but what folder should I save my two source file to? My rake task in in /lib/tasks/my_rake_task.rb.
Under rails convention, should the source files be saved there as well or is there a preferred location. Thanks.
Looks like any file loaded in the lib folders is loaded.
Related
Just to confirm, does running rake assets:precompile amalgamate all js and css files into application.css and application.js files under the public/assets directory? What is the purpose of this file? The reason I ask is because for some reason my development mode is running into a lot of asset loading conflicts with this file, but my production mode runs just fine. It seems that the only way I can get my application to serve assets properly in development environment is to delete these files.
Is there a configuration in my development.rb file that I can setup to prevent my application from relying on this file in development mode?
Using
rake assets:precompile:primary RAILS_ENV=production
instead of
rake assets:precompile
should prevent the assets without md5 being added to the public/assets directory - which should make sure the development mode assets are generated dynamically.
Quote
To stop the creation of the non-hashed filenames in public use:
rake assets:precompile:primary RAILS_ENV=production
from:
Why does rails precompile task do non-digest assets
My setup is fairly simple default rails 3.2.1 setup. All my .css.sass files are in /app/assets/stylesheets/. I have the sass-rails '~> 3.2.3' gem in :assets group.
There's no application.css, just main.css.sass (used for main layout).
When i issue:
RAILS_ENV=production bundle exec rake assets:precompile
it compiles my coffeescripts and javascripts. There are no error messages in the log. It's like it doesn't even try to compile sass files.
The main.css.sass file header looks like this:
//=depend_on "_globals.css.sass"
#import globals
The _glocals.css.sass exists in the same directory.
James is right and it's one of the possible solutions.
The drawback of adding all files to one manifest file is that all will be precompiled to single file - which isn't always what you want.
In my case I needed separate files (one file for each layout).
Heres how to add new manifest files:
config.assets.precompile += %w( file1.css file2.css )
You don't need to have actual file1.css, if you have file1.css.sass it will be precompiled.
I think sass needs a manifest file and by default that's application.css for a rails 3.2 app. So creating application.css and //= require 'main' might dove your problem.
I tried rake gem:unpack but I get task not found. I would like to have refinery gems in my /vendor directory to be able to see the never ending views and partials and may be modify them.
I'm still learning how to do things the "Rails way", but I feel your need to have the files in a directory that's easy to see. One command I found that will dump in vendor in the local project is bundle install --deployment. You'll need to run this after initially doing a bundle install.
run bundle package
more here: http://gembundler.com/bundle_package.html
I am creating a gem for a Rails project and I got some troubles to
understand how generators and initializers work.
I would like to
initialize my module loading some stuff from the database from models
related to tables my gem should create with a migration file.
Problem is : if I create a Railtie and put it my gem lib directory,
when I try to run my generator (to create the migration template file
for example), it's already trying to run the Railtie even though
tables required don't exist yet (because the migration file has not been executed yet).
How to restrict the "scope" of the Railtie ? I would like it only to
run when booting Rails from a server (webrick, thin, ...) or from the
console, but not for any rake tasks (including generators). I think
that rake tasks (like generators) load the entire Rails environment
and my problem should come from that.
Is there a simpler way to do what I want ?
any help or advice appreciated.
I have a rails 3.0.5 app and I'm setting up capistrano to use a recipe.
in my config directory I have a file named "database_capistrano.rb" and in my deploy.rb, also in config directory, I have the following line, just in the beginning:
require 'database_capistrano'
But I'm getting:
`require': no such file to load -- capistrano_database (LoadError)
Also try with:
require 'database_capistrano.rb'
And don't work...
How, in Rails 3.0.5, include files in capistrano deploy.rb??
Ok, I manage to find out how this should be done.
Just copied the file to a new sub-directory "deploy", for organization only, and at the beginning of my deploy.rb, added:
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), 'deploy')
Then, in deploy.rb, just used:
require 'database_capistrano'
For future visitors, I got better results with the answer found in Capistrano: deploy.rb file refactoring
i.e instead of require, use load. As long as that file is a gem in the bundle or a file that requires other gems that are in bundle, this will work.
To be frank, I didn't try the accepted answer, half because it looked a little workaround-ish, and half because I didnt fully understand how to adapt it for my situation