Hey guys,
I''m relatively new to rails, so forgive me if this is something
covered elsewhere.
One of the things that''s quite nice about JSP development, is the
large number of tag libraries that are available, in particular the
display tag (www.displaytag.org). Ruby and ActiveRecord will make
building a library like this almost too easy for words. However I''m a
little confused about how one would go about ''callling'' it.
The basic display tag call is:
<display:table name="test" />
Which translates rather simply to:
<%= display_table(@test) %>
But a more complicated call involves passing in some more information
<display:table name="test">
<display:column property="id" title="ID" />
<display:column property="name" />
<display:column property="email" />
<display:column property="status" />
<display:column property="description"
title="Comments"/>
</display:table>
How would you recommending handling this situation. The sub tags
will place a number of objects into the parent tag''s context.
but doing this inline in erb seems a little more difficult
display_table(@test, [Column.new("id", "ID"),
Column.new("name"),
Column.new(...)...])
So say I wanted to produce a library to allow generation of tables
with sorting, paging etc. How should I expect people to call it?
# From helpers?
provide a ''standard'' ruby class library, which can be called
from
helper methods for each controller
# inline erb functions
Provide a procedural API which takes Strings, Arrays and Hashes as
arguments allowing easier inline calling.
# something else?
I feel my Java background may mean I''m missing a
''ruby-like'' way of
achieving this.
--
Cheers
Koz
Hi Michael, On Mon, 22 Nov 2004 22:02:53 +1300, Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So say I wanted to produce a library to allow generation of tables > with sorting, paging etc. How should I expect people to call it?Have you had a look at raphinou''s TableHelper?[1] His approach[2] is to build TableFields objects in the controller, and then render them with a single call to table() in the view.> -- > Cheers > > KozSam [1] http://tablehelper.rubyforge.org/ [2] http://www.raphinou.com/rails/table_demo/index/
On Mon, 22 Nov 2004 22:02:53 +1300, Michael Koziarski <koziarski-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> The basic display tag call is: > > <display:table name="test" /> > > Which translates rather simply to: > > <%= display_table(@test) %> > > But a more complicated call involves passing in some more information > > <display:table name="test"> > <display:column property="id" title="ID" /> > <display:column property="name" /> > <display:column property="email" /> > <display:column property="status" /> > <display:column property="description" title="Comments"/> > </display:table> > > How would you recommending handling this situation. The sub tags > will place a number of objects into the parent tag''s context.You could make the ''display_table'' method take a block, so you could do: <%display_table(@test) do |data| display_column(data.id, ''title'' => ''ID'') display_column(data.name) display_column(data.email) display_column(data.status) display_column(data.description, ''title'' => ''Comments'') end %> Just define the methods as: def display_table(data_collection, &block) #do some stuff here to set up the table data_collection.each do |item| yield(item) end #do some stuff to close the table end def display_column(data, options) #perform functions to output one table cell end Obviously, this isn''t the complete solution, but it''s a start. There may be a _better_ way to do this, though---this is just what jumped into my mind as I read your message. YMMV -- Regards, John Wilger ----------- Alice came to a fork in the road. "Which road do I take?" she asked. "Where do you want to go?" responded the Cheshire cat. "I don''t know," Alice answered. "Then," said the cat, "it doesn''t matter." - Lewis Carrol, Alice in Wonderland