Tag: Ruby on Rails

  • The magic of Bundler

    Recently I reported a bug for Formtastic. Justin French, the author of Formtastic, created a branch and made a fix. He then asked me for my feedback. I look at the code and then decided to give it a try. In a pre-Bundler world that would have required this: Find a directory to play with […]

  • Redirecting back

    It’s very common in Rails CRUD to have a create and update actions that redirect back to the show action. The idea is that you show an object, click edit, save, go back to showing said objects with your changes. All is fine until you have an edit link somewhere else. Let’s say you have […]

  • Generating sample data

    As I’ve said in previous posts, I like being able to generate sample data for the projects I’m working on very quickly. It allows new developers to get up to speed fast, and new developers to move faster. When I don’t have a sample data generation method, I’m always scare to try whether, for example, […]

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

  • 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 […]

  • Hashes for select

    In Ruby on Rails there’s a very easy way to create a select tag: form.select(“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: form.select(“period”, periods) I was surprised to find out that the […]

  • Show a devise log in form in another page

    Show a devise log in form in another page

    Update: there’s a new version of this post covering Devise 4.0.0: Show a devise log in or sign up forms in another page Devise create various forms, among them one for signing up and one for logging in of course. These are the forms as they are generated in Devise 1.0.8: and If you try to […]

  • My first contribution to Rails

    https://rails.lighthouseapp.com/projects/8994-ruby-on-rails/tickets/4809 Looking forward to many others.