10
Oct
When using the S3 method of storage for paperclip, the last thing you want is to incur extra charges just for running your tests.
If you want to simply mock the storage aspect completely, and I'm not saying you do, but *if* you do, just do this:
@your_model.should_receive(:save_attached_files).and_return(true)
10
Mar
Pratik's HOWTO for Rails 2.3 templates is pretty thorough but did not include support for something I needed to do.
What I found is that I wanted to install a number of gems in a template. Simply adding the gem like this:
gem 'term-ansicolor'
resulted in an error!
rake aborted! A key is required to write a cookie containing the session data. Use config.action_controller.session = { :key => "_myapp_session", :secret => "some secret phrase" } in config/environment.rb
Before trying to hack up my own solution to add this line to
25
Feb
For those of you still using attachment_fu. (Please! No flames about using paperclip.) There are a few reasons you might need to create an attachment using a temp file. In our case, we were working on a system that has no write privileges except for the tmp directories. For the sake of this example, let's say I'm creating an archive file, writing it to the tmp dir, and I want to store it on S3.
Clearly, the quickest way to get the archive to S3 was to create an attachable object with the archive and save it. Husein knows
13
Jan
Sometime last summer, I visited Prague, Munich and Budapest a few times. Wanting to learn enough conversational German, Czech and Hungarian I had the idea that if I put the words in front of my face repeatedly while doing other tasks, I could learn enough to at least be polite.
The quickest way to do that was to hire a small child to hold up flashcards, but obviously that would have been highly questionable, so I used growl and ruby instead.
I created a quick gem called flashcards instead. Check it out. Assuming you have growl and rubygems
17
Aug
will_paginate is just one example of a truly well thought out plugin. It's easy to use and it doesn't get in your way if you want to do something for advanced than the default provides. Thanks Mislav!
There are a bunch of options to the view helper method #will_paginate that can make customizing the pagination links really easy.
Here they are:
@@pagination_options = { :class => 'pagination', :previous_label => '« Previous', :next_label => 'Next »', :inner_window => 4,
17
Aug
Polymorphism and Single Table Inheritance are both totally awesome, but there's a small trick if you want them to play nice with each other.
Say you have a model Post that's the base class for BlogPost. Bear with me, it's just an example.
Say you also want to associate comments which are polymorphic with the posts. Easy enough right? Sort of.
Most likely you're going to add a form for a comment onto your post show page. If you're POSTing to a comments controller, you're going to need to provide the #type and #id of the post in the form
17
Aug
You're using Rspec to test your helpers or views. You may have noticed that if you're providing an object without the url helper method, you're relying on actionpack to figure the routing path out for you.
link_to(@post, @post)
Hopefully you have #to_s method on your post that takes care of the first @post, but the second is considerably more troublesome. You'll notice this in your specs if you're using a mock_model to test the helper method.
In your helper you have:
def primary_link(post) link_to(post, post) end
In Your spec you have:
@post = mock_model(Post, :to_param
16
Jul
If you're like me and you're using active_record on merb because you didn't want to take the time to hack data_mapper 0.9.2 to work with merb 0.9.3 (not EDGE), you might run into a problem when using merbful_authentication.
The migration generated for the user model uses the singular_name for the drop_table rather than plural_name. This, obviously, causes an error when migrating down.
Here's the patch:
http://rubyforge.org/tracker/index.php?func=detail&aid=19856&group_id=5072&atid=19607
15
Jul
I released a ruby gem today that acts as a full api wrapper for discogs.com. See http://www.discogs.com/help/api for more information.
On rubyforge or here
artist = Discog::Artist.new('Broken Social Scene') puts " Artist: #{artist.name} Members: #{artist.members} Images: #{artist.images} URLs: #{artist.urls} Releases: #{artist.releases.map{|r| r.title }} " release = Discog::Release.new('188365') puts " Title: #{release.title} Labels: #{release.labels} Format: #{release.formats} Status: #{release.discog_status} Genres: #{release.genres} Styles: #{release.styles} Country: #{release.country} ReleaseDate: #{release.released} Tracks #{release.tracks} Images: #{release.images} Extras: #{release.contributors.join(', ')} " label = Discog::Label.new(ARGV[0]) puts " Name: #{label.name} Images: #{label.images} Contact: #{label.contact_info} Profile: #{label.profile} URLs: #{label.urls} Parent: #{label.parent} SubLabels: #{label.sublabels} Releases: #{label.releases} "