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
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