RubyFlow : The Ruby Community Blog

Home   Submit   Sign Up   Log In   leaders   Twitter   RSS Feed  

jalkoby — 7 posts

Get more from ActiveRecord::Store
You like ActiveRecord::Store with it's serialised attributes but tired from converting attributes to a not string value?! Check out active_store_accessor which does all dirty work for you.

PS. default values are also supported.
In this post you will find few useful ways of inserting variables into strings
If you like me work on a big & long-term rails project, you probably tired with an old migrations. Applying them takes a few minutes, sometimes you need to update them(changes in ActiveRecord). Manual removing them is hard & sometimes dangerous work, so checkout squasher gem which will do this job for you.
Sum in Rails
Read about #sum methods existed in Ruby on Rails
You using fabric(FactoryGirl, Fabrication, Machinist) in your test suite and test takes a few minutes to run. It's bad. The good news is this article helps to make your test run at least 2x faster without adding anything else. Really, just FactoryGirl & ActiveRecord.
After 3 years working with Rails I've noticed that my controllers have a lot statements like this:

def index
render :partial => "_partial", :locals => { ... } if request.xhr?
# or
render :ajax_template if request.xhr?

As for me it's a duplication. The similar situation was in Rails 2 in responding with proper format. In Rails 3 this issue was solved with respond_to & respond_with methods. If you agree with me take a look to Rjax gem that solves problem with ajax response.
If you worked with other languages you probably familiar with feature called multi dispatching or multimethods. It is the feature of some object-oriented programming languages in which a function or method can be dynamically dispatched based on the run time (dynamic) type of more than one of its arguments.

For example in C# it will be:

public void Multi(D d, A a) { System.Console.WriteLine("DA"); }
public void Multi(D d, B b) { System.Console.WriteLine("DB"); }
public void Multi(D d, C c) { System.Console.WriteLine("DC"); }
public void Multi(E e, A a) { System.Console.WriteLine("EA"); }
public void Multi(E e, B b) { System.Console.WriteLine("EB"); }
public void Multi(E e, C c) { System.Console.WriteLine("EC"); }

If you like the idea and want to add it to your ruby code check out multidispatch_dsl