Rails server will not start after install of paperclip. I have this error message in the console:
undefined method 'has_attached_file'.
In my Gemfile
gem "paperclip", :git => "http://github.com/thoughtbot/paperclip.git"
I tried this in my config/environments/development.rb
config.gem "paperclip"
and this in my config/application.rb
Paperclip::Railtie.insert
I have ImageMagik installed on my computer (I'm on windows 10). Any clue ?
I had a message in the console after install of paperclip, saying that paperclip is now compatible with aws-sdk >= 2.0.0. So I also set the latest aws-sdk-ruby from github...
EDIT : also tried this after getting the path with the command 'which convert'
Paperclip.options[:command_path] = "/c/Program Files/ImageMagick-7.0.7-Q16/convert"
First thing I'd change is to use a version number instead of getting the package directly from GitHub.
in Gemfile:
Change
gem "paperclip", :git => "http://github.com/thoughtbot/paperclip.git"
To
gem "paperclip", "~> 6.0"
Make sure to run the rails generate paperclip command (example: rails generate paperclip photo image) to add the needed attachment field to your database model schema.
Once you have the attachment field you can use has_attached_file to mount paperclip to that field (example: has_attached_file :image).
And don't forget to restart your server.
P.S: There's no need to use config.gem "paperclip" and Paperclip::Railtie.insert, I wasn't able to find any mention of them in the GitHub Paperclip documentation so I'm sure they are discontinued now as they were used in pre Rails 4 applications.
P.P.S: I would strongly recommend you dual boot to a Unix operating system (be it a Linux distribution or macOS) or use an online IDE such as Cloud9 instead of using Windows. It's simply a bad idea and while working on your project you want to replicate to the smallest detail your production environment.
Try to add
include Paperclip::Glue
to your Model.
I'm all set now. Apparently there was a problem with the database construction. For the rest, everything is well explained on github https://github.com/thoughtbot/paperclip but 1) I was following a tutorial with a few steps missing and 2) there was a specific problem for windows.
Dropping all the tables and migrating again from scratch seems to have solved the very basic problem which caused the error.
Windows users, pay attention to your path setting of the file.exe which has nothing to do with ImageMagik. You can place this file.exe anywhere you want, in my case
Paperclip.options[:command_path] = 'C:\Sites\utils\GnuWin32\bin'
Thanks anyway!
Related
Is there a way to use a gem as a library in Rails 4?
I have tried putting in a gem folder after cloning into lib folder but this doesn't seem to be working
You can set local path to gem in your Gemfile if I clearly understood the problem.
# Gemfile
gem 'my_perfect_gem', path: './path/to/my_perfect_gem'
I think it's better to set local gem location only in development and test environments, so wrap this line in a group. Unfortunately you should restart your rails server any time you've updated the gem.
May be there is a better approach such as using your gem as a part of application in lib folder – Auto-loading lib files in Rails 4
I am using the fog gem to send carrierwave uploads to an AWS S3 bucket. That seems to be working fine, but when I try to run my cucumber tests I get:
You are using Excon 0.6.6. WebMock supports version >= 0.9.6
I have moved fog out of the test group in the gemfile (it's only in development and production). I've looked around for other people have thing problem, but I haven't been able to find anything.
My goal really would be to not use fog at all in the test suite, but just use the local file system.
It turns out that I was using an old version of fog. I had:
gem 'fog'
In my gemfile when I needed to have:
gem "fog", "~> 1.12.1"
That fixed this problem.
Yep, I was about to chime in and let you know as much. I think a bundle update fog would also do the trick (without needing to lock to anything in particular or change the gemfile). Glad you were able to get yourself back on track so easily though.
To help understand the source code of various gems I often want to place various puts statements in the source code or even try using the ruby debugger.
But whats the best way of doing this?
Do you clone the project from github and make changes locally, if so how do you "force" the use of the local cloned code over the local gem on your machine. Do I just create some scripts that explicitly require the path of the cloned repos folder?
Or do should I use rvm to create a temp gemset, download the gem and modify it directly?
Are there any other methods ive overlooked? How would this change for gems designed for use within rails projects.
The way I usually do it when I want to make changes to a Gem:
Fork the repository on Github
Check it out and create a new branch for local changes
Use Bundler to manage dependencies for the project which uses the Gem
Change one line in the Gemfile to make it use the forked version of the Gem:
gem "thegem", :git => "git://github.com/name/thegem.git", :branch => 'mybranch'
or
gem "thegem", :git => "file:///path/to/thegem", :branch => 'mybranch'
with /path/to/thegem being the path to your local working copy.
The advantage is that you now already have a the perfect infrastructure set up for contributing your changes through a pull request :)
With Bundler.
In a Rails app simply edit the Gemfile and add:
gem "gem_name", :path => "~/MyGems/gem_name"
PS: Bundler work with any Ruby project.
You can use rvm to create a temp gemset, download the gem and modify it directly. A fast way to view/modify a gem is using gemedit :
Install:
gem install gemedit
Usage:
gem edit devise
or: gem edit devise -e mate
This hasn't got anything to do with paperclip, btw.
I've upgraded to rails 3.2 from a early version of rails 3.
I was using the AWS:S3 class to create buckets and what not.
The following code was working inside a model:
AWS::S3::Base.establish_connection!(:access_key_id => ...blah blah blah
I was also requiring the gem in the model like so:
require 'aws/s3'
However now I've upgraded and have ran all the updates on blunder, I'm getting the error:
uninitialized constant AWS::S3::Base
...when trying to establish a connection to S3.
Does anyone know what this is happening and how to fix it. Thanks.
I know you said it doesn't have to do with Paperclip but are you also using Paperclip in addition to the s3 gem in your app? I don't think newer versions of Paperclip depend on the aws-s3 gem anymore and instead depend on the aws-sdk gem.
Try replacing the aws-s3 gem with the aws-sdk gem.
I want to use ebayapi gem (https://github.com/codyfauser/ebay) with my rails 3.1 application.
If I add the gem in the Gemfile, rails doesn't run.
/Users/ssk/.rvm/gems/ree-1.8.7-2011.03/gems/money-1.7.1/lib/support/cattr_accessor.rb:7:in `cattr_reader': undefined method `id2name' for {:instance_writer=>true}:Hash (NoMethodError)
I removed the ebayapi gem and tried "require 'ebay'" but it said that "no such file to load".
Ebayapi gem works only with money 1.7.1 and I think that conflicts with rails 3.1 (maybe 3.0 as well).
Is there a way to workaround?
Thanks.
Sam
If it's truly incompatible, and you're up to fixing it yourself, then fork the projects in question on github, and update your Gemfile to point to your git repo (or even a local path to make editing a lot easier).
Here's an example:
gem 'money', :path => "~/dev/ruby/gems/money"
# or
gem 'money', :git => "git://github.com/my_account/money.git"
Once you've fixed it, send a pull request to the original project so they can include the fix.