A nicer way to join my hash?

Hi,

@message = Message.new(params[:message]) @message.recipients = Volunteer.all(:conditions => "email IS NOT NULL
AND email <> ''", :group => "email").map{|v| v.email}.join(", ")

Or even this:

@message = Message.new(params[:message])

volunteers = Volunteer.all(:conditions => "email IS NOT NULL AND email <> ''", :group => "email")

# essentially the same as .map { |v| v.email } only letting ruby figure out the "v" part. @message.recipients = volunteers.map(&:email)

-- Josh http://iammrjoshua.com

Julian Leviston wrote:

No, &: is much slower and uglier

Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/

Julian Leviston wrote:

@message = Message.new(params[:message]) @message.recipients = Volunteer.all(:conditions => "email IS NOT NULL AND email <> ''", :group => "email").map{|v| v.email}.join(", ")

Whoa.. cool.. I'm gonna read up on Ruby basics, thanks heaps.

You might want rails basics, coz that contains SQL, ruby AND rails code

Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/

Project Euler!

Blog: http://random8.zenunit.com/ Learn rails: http://sensei.zenunit.com/