Rails Best Practices 6: Filters and helpers file

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

With the today’s post I shall conclude my series on Ruby On Rails Best Practices . This is not because the required topics are completed, but rather because after the release of Rails 3.0, some constructs have been changed and should be reviewed. Probably in future we will return to talk about best practices, but starting from the new features introduced in the current Rails version. But now I will...

Read more

Rails Best Practices 4: Put method in the right model

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

In today’s post I will show some optimization we can do for models. I’ll focus on how to put methods inside the right model and delegation to get a better code.1. Put method in the right modelIn our example, suppose we want to represent the animal world by creating a model Kind that represents types of animal and an Animal models representing animals. For each type (quadrupedal, bi...

Read more

Rails Best Practices 3: Increase Controller’s readability

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

[POST UPDATE ON 19/07/2010 - 15:45] Continuing our analysis of the Rails Best Practices today we’ll see two other tricks to make more readable method of the controller.1. Methods within modelSuppose we have the classic user registry defined in such a way that an admin user can enable or disable other users.The deactivate method inside user Controller may be defined as follows:123456789101112131415161718class UserCont...

Read more

Rails Best Practices 2: Move logic to model

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

Today we continue our analysis of the Rails Best Practices. In the previous post we saw Named Scope, Model Association and Following the same direction, in today’s post we’ll examine the use of Callback Model and Virtual Attribute.1. Virtual AttributeSuppose we have a customers list table defined as follows123456create_table "clients", :force => true do |t| t.string "first_name" t.string "last_name" t.string "street" ...

Read more

Rails Best Practices: introduction

Logo devnterface d88f51727b3053dd3115e1ef9c566ad79b4c2edb3cd208c06345fc37058bebd9

I’ve decided to dedicate a series of posts to Rails Best Practices because I think it is important to share in order to continuously improve the way you write programs.Write these posts will also be an opportunity for me to investigate my knowledge, so I invite you right now to follow this trip with me and contribute with your comments.This first post is just an introduction in which I want to highlight...

Read more