[Activerdf] the 'collection' data type

Benjamin Heitmann benjamin.heitmann at deri.org
Fri Apr 27 18:32:52 IST 2007


On Apr 27, 2007, at 4:43 PM, Mikael Lammentausta wrote:

> Cheers to the activerdf group, fantastic work!!

Thanks :)

> <%=
>   TEST::Shortcuts.find_all.map { |item|
>       "<li><a href=\"#{item.shortcutURL}\">#{item.label}</a></li>"
>   }
> %>
>
> However, this returns all items from the RDF to an array with only  
> one array member! The loop iterates only once, printing all the  
> items into a single <li> element instead of creating many.

So what you want to do, is print out all Shortcuts form the TEST  
namespace,
but print them inside of specific HTML, right ?

I cant remember right now what .map does, but you should try this:

1.) just try this code:
<%=
   TEST::Shortcuts.find_all.join(" ")
%>
This should output something, so that you know that you have the data  
in the store, and that everything else is okay.

2.) now for the stuff, that you really want to do:

find_all will return an array, and ruby arrays you can just be  
iterated with "each":

<%=
   TEST::Shortcuts.find_all.each { |item|
       "<li><a href=\"#{item.shortcutURL}\">#{item.label}</a></li>"
   }
%>

You can try stuff like this in an irb session , or if it is inside of  
rails, then you can start a rails console ("./scripts/console").


More information about the ActiveRDF mailing list