Rake db:migrate error - paperclip - ruby-on-rails

I have installed Paperclip but I have error when I try to run
rake db:migrate
after
rails generate paperclip asset photo
I get
cannot load such file -- paperclip/tasks/attachments
What is wrong? This folder exists with that file.

Try using:
bundle exec rake db:migrate

When I tried downloading it as a plugin (rails plugin install ... ), I saw the same problem. I deleted the plugins from vendor/plugins directory and then added the paperclip gem to gemfile (gem "paperclip", "~> 3.0") and everything now works. You may want to give it a try.

To make sure paperclip is loaded and the version which supports attachments, do
bundle show paperclip
Open the gem in text editor and check if paperclip/tasks/attachments.rb is present. If no, then the version of the gem needs to be upgraded or uninstall all paperclip gem versions and do a fresh install. paperclip-3.5.0 works.
If the version is correct and if it still throws error, include
require 'paperclip'
in your boot.rb.
This forces rails to include the gem at boot time.

Related

I'm developing a Ruby gem, how can I try it out locally with my Rails app?

I am developing a gem meant to be used with Rails projects and want to try it out locally with another Rails app of mine.
I built the gem with bundle exec rake release which put a .gem file in the /pkg directory.
Then, in my Rails app, I added the following to my gemfile
gem 'mygem', '0.1.1', path: '/Users/me/projects/mygem/ruby/pkg'
I then ran bundle install which said it installed the gem. When I do this, it removes the gem from the path. IDK where it went.
When I start the Rails app, it's like the gem isn't included at all.
Interestingly, if I add a version that doesn't even exist, it still says bundle install works fine. (Example: gem 'mygem', '0.1.2345', path: '/Users/me/projects/mygem/ruby/pkg')
What am I supposed to do to try out my Gem locally with a Rails app?
This question is different from How can I specify a local gem in my Gemfile? because I explicitly tell bundle in my Gemfile to use the local gem, with the path given, and it still doesn't work. When I run bundle install, it says
Using mygem 0.1.1 from source at /Users/me/projects/mygem/pkg
So you'd think it works right, but it still doesn't.
Interestly, if I try it with a version number that doesn't exist, like mygem 1.2.3, it still runs bundle install successfully, which is really weird and seems like a bug:
Using mygem 1.2.3 (was 0.1.1) from source at /Users/me/projects/mygem/pkg
I prefer to use the following when working on a local gem side-by-side with a Rails project:
gem 'foo',
:git => '/path/to/local/git/repo',
:branch => 'my-fancy-feature-branch'

Rails 4, Capistrano 3.0.0, cannot load such file -- deploy

I just ran bundle update and capistrano got updated to 3.0.0 but now when I run cap deploy I get an error and can't figure out how to fix this. I have been updating my server every day without problem until this update.
cap aborted!
cannot load such file -- deploy
/home/mark/rails_apps/myapp/Capfile:1:in `load'
/home/mark/rails_apps/myapp/Capfile:1:in `<top (required)>'
capfile
load 'deploy'
load 'deploy/assets'
load 'config/deploy' # remove this line to skip loading any of the default tasks
I had to gem uninstall capistrano and selected version 3.0.0
(i.e. downgraded the gem to 2.x)
I had to run
gem uninstall capistrano
then update the gemfile with
gem 'capistrano', '~> 2.15'
and then run to reinstall the correct version again with
bundle update capistrano
Make sure you are using bundle exec (most likely you have multiple gem versions of capistrano)
i.e.
bundle exec cap -T
Instead of downgrading to Capistrano 2 use the new configuration from the current version.
require "capistrano/bundler"
require "capistrano/rails/assets"
require "capistrano/rails/migrations"
See also this nice posting, which summarises the differences between Capistrano 2 and 3.
Add the related gems to your Gemfile
i.e. for
gem 'capistrano-bundler' # for capistrano/bundler
gem 'capistrano-rails' # for capistrano/rails/*
Do not downgrade to 2.x for this.
I had this problem today and pastullo's solution above fixed it except that I had to run gem uninstall capistrano (as markhorrocks answered) not bundle uninstall capistrano.
I also found this blog on bundler very useful: http://viget.com/extend/bundler-best-practices
Thanks for sharing this as it saved me heaps of time. x
The fastest way to fix this I have found is to backup the cap files (Capfile, config/deploy.rb, and config/deploy/*.rb) and then re capify (it's no longer called "capify"):
bundle exec cap install STAGES=staging,production
Then recreate your cap files from your backup. It will take you 5 minutes to do this and you'll be over the major Capistrano upgrade hump.
I used
bundle exec cap production deploy
instead of just cap production deploy
in my case I have changed my project ruby version. may be bundle also work here.
but I changed it to back what it was in previously.
ex:
rbenv local 2.4.1

Purpose of the sass-rails gem in rails

What is the purpose of the gem 'sass-rails' that is included by default in the :assets group of a new rails app ?
If I comment out that line I can still use .css.scss files without a problem.
You need it for sass/scss files. Clear your browser cache, clear rails cache (Rails.cache.clear in console), comment out the line, uninstall the gem (all versions), then restart your server. You'll get the following error:
no such file to load -- sass
Uncomment the line for the sass-rails gem, reinstall the gem and restart your server to make it work again.

Rails does not load gems from vendor/gems

I have strange old buggy project on Rails 2.
It have gem's dependencies in config/environment.rb like
config.gem "andand"
config.gem "json"
config.gem "chronic"
config.gem "mini_fb"
all those gems are located in vendor/gems/
andand-1.3.3/
chronic-0.6.7/
json-1.7.3/
mini_fb-1.1.7/
rbet-1.0.3/
redis-3.0.1/
responsys_client-0.0.1/
but when i start unicorn server with this app it always complain that it can't find this gems. Why?
UPDATE
After building and installing gem from vendor/gems rails still complain about it.
I have tweake mini_fb gem into custom mini_fb_custom gem. Changed all references in gemspec and other files from mini_fb to mini_fb_my, installed it and it is shown in gem list as mini_fb_my. But it fails to load from config/environment.rb and complains that
Missing these required gems:
mini_fb_my >= 0
maybe i should rename lib/mini_fb.rb to lib/mini_fb_my.rb
i'll check it.
UPDATE 2
Yes, renaming files rocks!
You still need to install them from those folders, or unicorn will not know where to look for them.
Just install the gems from that directory and unicorn should pick them up.
UPDATE
You can install your gems locally with this command
gem install --local vendor/gems/gem/gem-name.gem
On more recent versions of rails you just specify path on the Gemfile
gem "gem-name", path: "path/to/gem"
My advice: replace the obsolete gem configuration with bundler (it works fine with rails 2, there should be a tutorial for rails 2 available on their website).
Configuration through gem command, freezing gems, etc. is just pain in the a** and it seemed kinda buggy to me when I'd used it (long time ago).

Unpacked gem in vendor/gems not in a versioned directory

I unpacked a gem into my vendor/gems directory and tried to run my Rails app.
I got this message:
Unpacked gem in vendor/gems not in a versioned directory
I don't understand this error and judging by the Google search results for this error there are not many people who have experienced this problem.
Could this mean I also need to vendor Rails to use vendor/gems?
The much easier and more robust way is to use gem dependencies.
Then if you want to unpack your gems into vendor/gems its as easy as typing:
rake gems:unpack
You do not need to vendor rails in order to vendor gems, the error appears to be a user error you are decompressing the gem into the wrong location and missing some version info.
You don't need to vendor Rails to use vendor gems.
Normally gems unpack to a directory called something like vendor/gems/some_gem-1.2.3. Check that all your vendored gem directories follow this pattern (i.e. GEM_NAME-VERSION).
Did you do this manually or using rake? Since a gem in the vendor/gems directory has this format - gem-name-VERSION.
For example the ruby-openid gem will be unpacked to vendor/plugins/ruby-openid-2.1.7/.
Try using rake gems:unpack to unpack the gems.

Resources