Tag Archives: rails

Organizing coffeescript code in a Rails 3 app

Ever since Rails 3.1 adopted coffeescript within the asset pipeline as a default, coffescript has become an increasingly popular language for easily writing your javascript code. Despite a lot of tutorials out there on how to write coffee and take advantage of the Rails asset pipeline, there are rather few guidelines on how to properly … more

Posted in Blogs | Tagged , , , |

How to check if object can be destroyed if it has dependent: restrict associations

Rails provides several handy options for specifying how to deal with associated models upon deletion, for example: class Blog has_many :posts, :dependent => :destroy end The destroy value for the dependent option will call the destroy method for every post in the blog when the blog itself is destroyed. Other options are delete or nullify, … more

Posted in Blogs | Tagged |

Default request parameters in Rails functional tests

I was looking for an easy way to force every request in a functional test in Rails to use a set of parameters by default, regardless of being specified explicitly. This is, every time I write: it “should get index” do get :index end Rails should actually do: it “should get index” do get :index, … more

Posted in Blogs | Tagged |

Upgrading to Rails 3: @routes is nil

I’m currently in the process of upgrading an application from Rails 2 to Rails 3. Fortunately, it’s not the first time someone does so, and there’s plenty of resources throughout the web that will help you to work it out. In particular, I chose to follow the steps demonstrated by Ryan Bates in an outstanding … more

Posted in Blogs | Tagged , , , |

Install the RMagick gem in the painless way with Homebrew

Introduction Disclaimer: this section is just happy talking, if you want to get right to the beef, skip it and go right to the beef. Yesterday was a sad day for me. It wasn’t meant to be like that. I began the day with the intention of setting up a development environment for this amazing … more

Posted in Blogs | Tagged , , , , , |

Deleting children with accepts_nested_attributes_for in Rails

On the previous post I wrote a few lines on the basic usage of the accepts_nested_attributes_for method in rails models. I strongly recommend reading that post before this one if you haven’t. Although there is a standard way for deleting items, there is few information on how to deal with them on the model or … more

Posted in Blogs | Tagged , |

Handling children with accepts_nested_attributes_for in Rails

Rails makes it easy to build HTML forms associated to a certain model. Simply using the form_for instruction on the view, writing a simple update method in the controller and setting validation logic on the model, makes standard CRUD operations incredibly easy to code. Since version 2.3, Rails also provides a convenient way of dealing … more

Posted in Blogs | Tagged , |