Feeds:
Posts
Comments

Posts Tagged ‘rails’

In Rails the pluralizations are managed by the Inflector class: it knows that the plural of “user” is “users”, but the plural of “person” is “people”. To add new inflection rules, one can add new rules in the environment.rb, but it is important to add the Inflector.inflections block after the Initializer.run block.

ActiveSupport::Inflector.inflections do |inflect|
inflect.irregular [...]

Read Full Post »

Although the development of applications is fast in Rails, the applications themselves are often a bit slow. The elegant framework increases the productivity of the programmer but reduces the performance of the application. The DRY principle is great to prevent code repetition, but it is less optimal to increase speed: it is of course much [...]

Read Full Post »

If you want to add additional parameters to a link using a path helper, for example for nested restful resources, it is useful to use a hash. All additional parameters are added to the query string:

group_post_path(:group_id => group, :id => post)
>> /groups/4/posts/2
group_post_path(:group_id => group, :id => post, :option => 1)
>> /groups/4/posts/2?option=1

If [...]

Read Full Post »

The counter cache for belongs_to associations is a useful Rails feature to speed up your application. It allows to cache the number of objects which belong to the associated class. All you need to do is to add :counter_cache => true to the belongs_to association:

class Comment
belongs_to :post, :counter_cache => true

And you need to [...]

Read Full Post »

The modules and mixins in Ruby are a good way to implement AOP in Ruby. Typical AOP examples are debugging and logging. Modules allow you to weave in aspects of code in different classes – exactly what you need for AOP. Ruby offers full support: “extend” is used to add methods from modules as class [...]

Read Full Post »

There are a couple of functions which you have to look up in any
language again and again, because they are slighty different in
each language, especially those for formatting of dates and
floating point numbers.
To display dates and datetimes in different formats in Ruby on
Rails applications, the following list for default formats
may help. The default date formats [...]

Read Full Post »

If you want to tackle challenging tasks, for example climbing a big mountain, you have the choice: either you join a large climbing team and use a lot of expensive equipment, or you try it alone using free climbing.
In the software world, the task is the software to be written, the climbing equipment are the [...]

Read Full Post »

Rails Conference Europe 2008 is over and the slides are available here. In my opinion the best talks were the ones from Yehuda Katz about jQuery and from Justin Gehtland about Small Things, Loosely Joined, Written Fast. Both are great speakers and the talks were awesome.

Read Full Post »