Using Paperclip with Padrino App

104 views
Skip to first unread message

Jared

unread,
Dec 22, 2011, 3:48:55 PM12/22/11
to Mad Railers, the Madison, WI Ruby on Rails Users Group
I know this isn't a Rails specific question, but I thought you guys
might know how to fix this.

Background: I'm building a simple blog using Padrino, Ruby 1.9.2,
HAML, and Heroku. I want the posts index to have a magazine-like look
to it. For each post in the index, the user should see titles, content
teasers, and images. My problem is with attaching the images.

Problem: I've been trying to use the Paperclip gem to attach an image
to each post. Heroku will fish the actual image from an Amazon S3 bin.
So far, when I try to run a migration, I get the error:

$ .../base.rb:1088:in `method_missing': undefined method
`has_attached_file' for #<Class:0xa672140> (NoMethodError)

It looks like Paperclip just won't load, but there's where I get
stuck.

Details:
--Q: What am I doing when I "try to run a migration"?
--A: I put the following into the migrations folder

class AddPictureToPost < ActiveRecord::Migration
def self.up
change_table :posts do |t|
t.has_attached_file :picture
end
end

def self.down
drop_attached_file :posts, :picture
end
end

then run "padrino rake ar:migrate"

--Q: Do I have Paperclip listed in the Gemfile?
--A: Yes.

--Q: What does the post model look like?
--A:

class Post < ActiveRecord::Base
has_attached_file :picture,
:storage => :s3,
:bucket => 'blog_images',
:s3_credentials => {
:access_key_id => ENV['S3_KEY'],
:secret_access_key => ENV['S3_SECRET']
}
end

--Q: What does the app.rb look like?
--A:
class Blog < Padrino::Application
register Padrino::Rendering
register Padrino::Mailer
register Padrino::Helpers

enable :sessions

get '/' do
haml :index
end
end

--Q: What does boot.rb look like?
--A:
PADRINO_ENV = ENV["PADRINO_ENV"] ||= ENV["RACK_ENV"] ||=
"development" unless defined?(PADRINO_ENV)
PADRINO_ROOT = File.expand_path('../..', __FILE__) unless defined?
(PADRINO_ROOT)

require 'rubygems' unless defined?(Gem)
require 'bundler/setup'
Bundler.require(:default, PADRINO_ENV)

Padrino.before_load do
end

Padrino.after_load do
end

Padrino.load!

--Q: What does the full error output look like?
--A:
jared:~/blog$ padrino rake ar:migrate
=> Executing Rake ar:migrate ...
/usr/local/lib/ruby/gems/1.9.1/gems/activerecord-3.1.3/lib/
active_record/base.rb:1088:in `method_missing': undefined method
`has_attached_file' for #<Class:0xa1ffb30> (NoMethodError)
from /home/jared/isthmus2/app/models/post.rb:2:in `<class:Post>'
from /home/jared/isthmus2/app/models/post.rb:1:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `block in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:223:in `block in load_dependency'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:640:in `new_constants_in'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:223:in `load_dependency'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/reloader.rb:148:in `safe_load'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:162:in `block in require_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:160:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:160:in `require_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/application.rb:34:in `inherited'
from /home/jared/blog/app/app.rb:1:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `block in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:223:in `block in load_dependency'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:640:in `new_constants_in'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:223:in `load_dependency'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/reloader.rb:148:in `safe_load'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:162:in `block in require_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:160:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:160:in `require_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/mounter.rb:148:in `locate_app_object'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/mounter.rb:30:in `initialize'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/mounter.rb:221:in `new'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/mounter.rb:221:in `mount'
from /home/jared/blog/config/apps.rb:34:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `block in require'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:223:in `block in load_dependency'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:640:in `new_constants_in'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:223:in `load_dependency'
from /usr/local/lib/ruby/gems/1.9.1/gems/activesupport-3.1.3/lib/
active_support/dependencies.rb:240:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/reloader.rb:148:in `safe_load'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:162:in `block in require_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:160:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:160:in `require_dependencies'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:70:in `block in load!'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:70:in `each'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/loader.rb:70:in `load!'
from /home/jared/blog/config/boot.rb:29:in `<top (required)>'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/cli/base.rb:56:in `require'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/cli/base.rb:56:in `block in rake'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/cli/base.rb:140:in `capture'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/lib/
padrino-core/cli/base.rb:56:in `rake'
from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/task.rb:
22:in `run'
from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/
invocation.rb:118:in `invoke_task'
from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor.rb:
263:in `dispatch'
from /usr/local/lib/ruby/gems/1.9.1/gems/thor-0.14.6/lib/thor/base.rb:
389:in `start'
from /usr/local/lib/ruby/gems/1.9.1/gems/padrino-core-0.10.5/bin/
padrino:9:in `<top (required)>'
from /usr/local/bin/padrino:19:in `load'
from /usr/local/bin/padrino:19:in `<main>'

If you've read this far...THANKS! I hope you can help me shed some
light on this.

Best,
-Jared

Bradley Grzesiak

unread,
Dec 22, 2011, 4:02:13 PM12/22/11
to mad-r...@googlegroups.com
FWIW, despite the name, we are definitely not Rails-specific, but rather Ruby-specific. We just like the name. =)

Anyway, sorry, but I can't help you on Padrino. :/

:brad

-Jared

--
You received this message because you are subscribed to the Google Groups "Mad Railers, the Madison, WI Ruby on Rails Users Group" group.
To visit the Madison Rails Home page, go to http://madisonrails.com/
To post to this group, send email to Mad-R...@googlegroups.com
To unsubscribe from this group, send email to Mad-Railers...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/Mad-Railers?hl=en



--
Bradley Grzesiak
founder, bendyworks llc
http://bendyworks.com/
Reply all
Reply to author
Forward
0 new messages