Forum: Radiant CMS Custom Radiant Tags

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-02-03 17:12
  tag 'kids:kid_sport_list' do |tag|
    kid = tag.locals.kid
    kid.sports.each do |sport|
    %{#{sport.name})
    end
  end

For some reason this outputs a "#" for each sport in kid.sports instead
of the name... Would anyone know why?
09477c358c5897d44121a248326e16d7?d=identicon&s=25 Jim Gay (Guest)
on 2009-02-03 17:18
(Received via mailing list)
On Feb 3, 2009, at 11:12 AM, Little Known wrote:

>  tag 'kids:kid_sport_list' do |tag|
>    kid = tag.locals.kid
>    kid.sports.each do |sport|
>    %{#{sport.name})
>    end
>  end
>
> For some reason this outputs a "#" for each sport in kid.sports
> instead
> of the name... Would anyone know why?

looks like you have a ) where you should have a }
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-02-03 17:24
Jim Gay wrote:
> On Feb 3, 2009, at 11:12 AM, Little Known wrote:
>
>>  tag 'kids:kid_sport_list' do |tag|
>>    kid = tag.locals.kid
>>    kid.sports.each do |sport|
>>    %{#{sport.name})
>>    end
>>  end
>>
>> For some reason this outputs a "#" for each sport in kid.sports
>> instead
>> of the name... Would anyone know why?
>
> looks like you have a ) where you should have a }

That's just a result of me typing wrong on this forum, not causing the
problem. Its correct in my code.
8802b1fa1b53e2197beea9454244f847?d=identicon&s=25 Sean Cribbs (seancribbs)
on 2009-02-03 17:31
(Received via mailing list)
Also, each just iterates over the collection and then returns the
original collection.  You'll want to use map/collect or inject instead.

tag 'kids:kid_sport_list' do |tag|
  kid = tag.locals.kid
  kid.sports.map {|s| s.name.to_s }.join(", ")
end

Sean
09477c358c5897d44121a248326e16d7?d=identicon&s=25 Jim Gay (Guest)
on 2009-02-03 17:34
(Received via mailing list)
On Feb 3, 2009, at 11:24 AM, Little Known wrote:

>>> For some reason this outputs a "#" for each sport in kid.sports
>>> instead
>>> of the name... Would anyone know why?
>>
>> looks like you have a ) where you should have a }
>
> That's just a result of me typing wrong on this forum, not causing the
> problem. Its correct in my code.


tag 'kids:kid_sport_list' do |tag|
   kid = tag.locals.kid
   result = []
   kid.sports.each do |sport|
     result << sport.name
   end
   result.join(' ')
end
222784b8a601c9e9786cd0291e58fb7a?d=identicon&s=25 Little Known (littleknown)
on 2009-02-03 18:07
Thank you, very helpful!
This topic is locked and can not be replied to.