Archive for the ‘Ruby on Rails’ Category

Caching Locale-specific Dynamic JavaScript Files

I was recently inspired to create some cached, dynamic JavaScript files for a project I am working on after watching Ryan Bates Railscasts episodes 88 and 89.
The basic concept is to create a JavaScript controller that dynamically renders some JavaScript file(s). This allows you to take advantage of ERB in your JavaScript files. [...]

Read the rest of this entry »

GoRuCo 2008

Next week I will be traveling to New York for the Gotham Ruby Conference courtesy of my favorite Ruby on Rails consulting company in Phoenix. I’ll be attending with Integrum’s resident Agile methodology expert. If you’re in NY or attending the conference, be sure to look us up – see my contact information.

Read the rest of this entry »

Rails Tip: Precision and scale for decimals

For when you need that little bit of extra accuracy, specifying precision and scale for a decimal column in your Ruby on Rails migration is pretty simple. The precision represents the total number of digits in the number, whereas scale represents the number of digits following the decimal point. To specify the precision [...]

Read the rest of this entry »

Rails counter_cache problem

I ran into a strange Ruby on Rails counter_cache problem today. Given the following example models:
class Poll < ActiveRecord::Base
has_many :poll_choices
has_many :poll_votes
end

class PollChoice < ActiveRecord::Base
belongs_to :poll
has_many :poll_votes
end

class PollVote < ActiveRecord::Base
belongs_to :poll, :counter_cache => :votes_count
belongs_to :poll_choice, :counter_cache => :votes_count
end
We want to ensure that the Poll [...]

Read the rest of this entry »

The Tip of the Ruby #1

I was recently asked about the difference between using or versus || in Ruby and thought it might make a good tip. They essentially do the same thing, but with one difference: operator precedence. You see || is evaluated before an assignment whereas or is evaluated after an assignment. This is why you [...]

Read the rest of this entry »

Discover your missing specs

Have you ever had the feeling that something was missing, but you weren’t quite sure what it was? I was looking at my code coverage the other day and thought to myself that it seemed like I was missing something. Rather than go through each file manually to see if it had an [...]

Read the rest of this entry »

Gravatar Problems

When I switched the blog to Mephisto I had installed the Gravatar caching plugin. It seemed to be working fine prior to deployment, but once in production it was not working as expected. Today I finally tried to track down what was wrong. hopefully this will fix any problems with Gravatar images, [...]

Read the rest of this entry »

Testing a helper with a block

I’ve been doing a lot of Rspec testing lately. Although I’ve been using it for a while to do BDD I realize that I have not been testing things as well as I should. Yesterday I was trying to add tests for a helper method that ensures the passed in block is only [...]

Read the rest of this entry »

Stubbing controller methods in a helper test

I hadn’t created any tests of helper methods in Rspec until last week. Doing so I found that one of my helpers was invoking the restful_authentication logged_in? method. This probably isn’t a big thing, but I was unsure how to stub the logged_in? method, that is, how to get the controller context to [...]

Read the rest of this entry »

Userstamps

In my last article I talked about adding a deleted_at field to the migration timestamps method for use with acts_as_paranoid. One of the additional things I wanted to do was not only capture the timestamp information, but also the user information. This way, I can be really paranoid and see who did what [...]

Read the rest of this entry »