Month: September 2010

  • Deleting all records in a Rails project

    During the initial phase of development of a Rails application I don’t use migrations as migrations but as table definitions. Until I deploy I feel free to modify the migration files as much as I want and I have one per table. The downside of that is that the only way to apply the changes […]

  • undefined method `authenticate?'

    If you are getting this error: ActionView::Template::Error: undefined method `authenticate?’ for nil:NilClass in your call to Devise’s user_signed_in? or similar, you probably forgot to add this: class ActionController::TestCase include Devise::TestHelpers end at the bottom of the test_helper.rb file. Not that that would ever happen to me…

  • I suddenly love my… ISP

    People, including me, tend to make a big deal of bad stuff and not of good stuff, so I sometimes try to do the oposite. Recently my internet connection was slow, very slow. Several weeks passed and I’ve got really angry so I did complaint, expecting to be ignored. I wasn’t ignored, I’ve got an […]

  • Better assert difference?

    Rails come with some awesome assertion methods for writing tests: assert_difference(“User.count”, +1) do create_a_user end That asserts that the count of user was incremented by one. The plus sign is not needed, that’s just an integer, I add it to make things clear. You can mix several of this expressions into one assert_difference: assert_difference([“User.count”, “Profile.count”], […]

  • Redirect to SSL in Rails applications

    I’ve looked at the various ssl_requirement repositories out there. I concluded the most modern and maintained version is yardstick’s which is released as a gem called sslrequirement, but I’ve failed to use it properly. So I just did it by hand. First, we need a simple method that will let us know whether SSL is […]

  • My hypothesis of music appreciation

    I believe most music we like we like by association. What I mean by that is that we don’t like the music because of the music itself but because of what we associate to it. We probably do that with most stuff but if you think about it, shouldn’t music taste vary much more from […]

  • Cron jobs for web applications

    I always dislike setting up cron jobs for web applications. The whole application lives in /var/www but I manually create this single line somewhere else that I have to remember to setup if I switch servers, and turn off if needed, and maintain accordingly. Well, it so happens that it can be done much better […]

  • Hashes for select

    In Ruby on Rails there’s a very easy way to create a select tag:“period”, [[“Month”, 1], [“Year”, 12]]) In my case I have the options in a hash, like: periods = { 1 => “Month”, 12 => “Year” } but when I did this:“period”, periods) I was surprised to find out that the […]