Hi all, i''m trying to email multiple people based on certain criteria. i do a search like @stacks = Group.find(:all, :conditions => ["component_id = ?", 2]) this populates stack to contain multiple groups with component_id =2. How do i populate @recipients to contain all possible @stack.email. Let me clearify. Each stack has its own email, and i need to include each stack.email into @recipients. i''ve been trying to do @stacks.each do |stack| @recipients = stack.email end But i know this is wrong, but i think it''s a step in the right direction Please help if possible, yng -- Posted via http://www.ruby-forum.com/.
@recipients = Array.new @stacks.each do |stack| @recipients << stack.email end would do the trick. If you only want to load the email attribute you can use a finder that only loads that field as well. On 7/17/06, yngwie <mdalsant@gmail.com> wrote:> > Hi all, > > i''m trying to email multiple people based on certain criteria. > > i do a search like > > @stacks = Group.find(:all, :conditions => ["component_id = ?", 2]) > this populates stack to contain multiple groups with component_id =2. > How do i populate @recipients to contain all possible @stack.email. > > Let me clearify. Each stack has its own email, and i need to include > each stack.email into @recipients. > > i''ve been trying to do > > @stacks.each do |stack| > @recipients = stack.email > end > > But i know this is wrong, but i think it''s a step in the right direction > > Please help if possible, > yng > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060717/5f9d036b/attachment.html
You want to iterate through @stacks, adding the emails to an array:
@recipients = []
@stacks.each {|stack| @recipients << stack.email}
or, more directly:
@recipients = @stacks.map {|stack| stack.email}
- dan
--
Dan Kohn <mailto:dan@dankohn.com>
<http://www.dankohn.com/> <tel:+1-415-233-1000>
On Jul 17, 2006, at 12:03 PM, yngwie wrote:
> Hi all,
>
> i''m trying to email multiple people based on certain criteria.
>
> i do a search like
>
> @stacks = Group.find(:all, :conditions => ["component_id = ?",
2])
> this populates stack to contain multiple groups with component_id =2.
> How do i populate @recipients to contain all possible @stack.email.
>
> Let me clearify. Each stack has its own email, and i need to include
> each stack.email into @recipients.
>
> i''ve been trying to do
>
> @stacks.each do |stack|
> @recipients = stack.email
> end
>
> But i know this is wrong, but i think it''s a step in the right
> direction
>
> Please help if possible,
> yng
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails