Notes posted by noniq
RSS feed
5 thanks
Makes it possible to use a scope through an association
This is a very useful method if you want to to use a scope through an association:
class Book < ActiveRecord::Base scope :available, where(:available => true) end class Author < ActiveRecord::Base has_many :books scope :with_available_books, joins(:books).merge(Book.available) end # Return all authors with at least one available book: Author.with_available_books
See http://asciicasts.com/episodes/215-advanced-queries-in-rails-3 for more info.

1 thank

2 thanks
Routing changes in Rails 3
See ActionDispatch::Routing for routing in Rails 3.

3 thanks
collect_with_index
Use Object#enum_for if you need to collect with index:
require 'enumerator' ['a', 'b', 'c'].enum_for(:each_with_index).collect do |item, index| "#{index}: #{item}" end
See also: Enumerable#each_with_index

0 thanks
collect_with_index
Use Object#enum_for if you need to collect with index:
require 'enumerator' %w{foo bar}.enum_for(:each_with_index).collect do |item, index| "#{index}: #{item}" end
See also: Enumerable#each_with_index