IN NEED OF EXPLANATION:
class Comment < ActiveRecord::Base
validate :must_be_friends
def must_be_friends
errors.add_to_base("Must be friends to leave a comment")
unless commenter.friend_of?(commentee)
end
end
The above code comes from rails documentation. Ther
doing @foo.map(&:id) doesn't perform as well as @foo.map { |f|
> f.id } for big numbers of foos...
> Also note that this is a Rails only feature (ie: try it on plain irb
> and it will not work).
>
> On Mar 11, 1:35�pm, Hiro Protagonist http://www.ruby-forum.com/.
--~--~---
Hi all,
Can someone explain to me in terms of ruby why this works?
Story.find_all_by_user_id(2).collect(&:link)# 1 method call
This is in ROR console. link is a property of Story. The above command
finds all db rows and all their properties (columns) with user_id == 2
and creates an array
3 matches
Mail list logo