Skip to content

Instantly share code, notes, and snippets.

@karmi
Created December 12, 2008 16:03
Show Gist options
  • Select an option

  • Save karmi/35172 to your computer and use it in GitHub Desktop.

Select an option

Save karmi/35172 to your computer and use it in GitHub Desktop.
== Usage
Declare the association in your ActiveRecord model:
picturable_with_flickr
You can then attach/access/destroy your pictures (assuming there's a model +Book+ in your application):
Picturable.search( :text => 'My cute kitten' )
=> #<Flickr::Photos::PhotoResponse:0x300dc5c ... photos[#<Flickr::Photos::Photo:0x2fe6a30 ... @id="1234567890", ...
book = Books.first
book.pictures.create :flickr_id => '1234567890'
book.pictures.first
=> #<Picturable id: 1, description: "My cute kitten" ...
book.pictures.first.url
=> "/images/pictures/books/1/1234567890_t.jpg"
book.pictures.first.local_url(:square)
=> "/path/to/your/app/public/images/pictures/books/1/1234567890_s.jpg"
book.pictures.first.url(:large)
=> "http://farm4.static.flickr.com/1234/0000000000_1234567890_o.jpg"
# ....
# No authorization for bundled controller ...
# PicturableWithFlickr::AUTHORIZE = Proc.new { }
# ... or authorize with standard AuthenticatedSystem stuff
PicturableWithFlickr::AUTHORIZE = Proc.new { |controller| include AuthenticatedSystem; controller.send(:login_required) }
# ....
class PicturableController < ActionController::Base
include PicturableWithFlickr::Controller
layout 'picturable'
before_filter :authorize
before_filter :load_object
before_filter :set_search_string
before_filter :load_search_results
end
module PicturableWithFlickr
# def self.included(base)
# etc ...
module Controller
def index
#...
end
private
def authorize
PicturableWithFlickr::AUTHORIZE.call(self) if defined? PicturableWithFlickr::AUTHORIZE
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment