Created
December 12, 2008 16:03
-
-
Save karmi/35172 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| == 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" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # .... | |
| # 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) } | |
| # .... | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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