Category Archive: rails

Jan 14

Reloading models in Rails 3.1 when usign Spork and cache_classes = true

Speeding up you tests with Spork is very common when developping Rails applications. What Spork do is preloading your application in a server and copies a fork of that server whenever you run tests. It avoids reloading all the rails stack !! That is great !!! But the problem I ran into is that I …

Continue reading »

Nov 17

ActiveRecord like searching object in Rails form helpers

Ruby is a wonderful language. And Rails is a wonderful framework. Why ? Because of Duck typing !!! Example : You build a database application for a book store Books are classified by : Genre Author Country On a search page, you can search with a title text field, author select box, genre checkboxes. So …

Continue reading »

Oct 20

Ruby Rails : How to bypass skip validation in Devise

Since my last post with email validations, I was looking for a solution to integrate it with devise Sadly for me, devise implements the old way of validating email with regexp : # From devise gem version 1.1.3 validates_format_of :email, :with => email_regexp, :allow_blank => true Well, as I don’t want to hack activemodel’s code, …

Continue reading »

Aug 19

Enumerable grep method in Ruby

There is some methods that are not very known among ruby developpers. One of them is Enumerable#grep method. I would like to share one of the use case I have to face with, and how I implement grep. Purpose, I have a Hash representing a simple network I’d like to select all the people related …

Continue reading »

Jul 21

Email validation in Ruby On Rails 3 or Active model without regexp

In Rails 3.0, you can use custom validator in your active_record model. So I wanted to manage email validations without regexp matching like others do. I find a new way to make this work thanks to ruby mail gem, a dependency of Rails 3.0 I use this with devise, see my blogpost here : Ruby …

Continue reading »

Jul 07

How to translate your column fields and values with gettext in ruby on rails

I am proud to have published my first useful ruby gem. It is called gettext_column_mapping, you can check out the code in my github repository. I already released it as a gem through gemcutter/rubygems It is based upon Masao Mutoh (gettext and gettext_active_record) and Michael Grosser (fast_gettext and gettext_i18n_rails) works. Thanks to them History In …

Continue reading »

Jun 29

Bundler default Gemfile and custom Gemfile, example of wirble

Hi all, A simple trick I want to share with you if you are using Bundler (or rails 3) It matters if you want to install wirble gem in your workstation but not in your server Sometimes, you want to include some gem that are not mandatory for your application to run but you want …

Continue reading »

Mar 11

Mysql 4.x and Rails : RELEASE SAVEPOINT issue

Today with a project using mysql 4.1.22 that I have to implement some tests, I ran this error with rails 2.3.5 and I think for 2.3.x branch. Mysql::Error: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ‘RELEASE SAVEPOINT …

Continue reading »

Oct 08

gettext 2.0.4 and rails 2.3.4

Rails 2.3.4 broke gettext_activerecord 2.0.4 Well I did not test other gems of the mutoh gettext set of libraries but here is the gulty code that breaks rails. Since Activerecord::Errors changed its implementation a bit, an error like this is raised : NoMethodError: undefined method `gsub’ for #<ActiveRecord::Error:0×00000002919738> from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:165:in `localize_error_message’ from /home/hallelujah/Jail/lib/ruby/gems/1.9.1/gems/gettext_activerecord-2.0.4/lib/gettext_activerecord/validations.rb:112:in `block (2 …

Continue reading »