B
Bauduin Raphael
Hi,
I'm trying to develop a Rails component to display a Ruby array as a
html table (which could evolve in something equivalent to CKHTMLTable
for cgikit).
I use a helper:
#Helper method that can be used in the main template:
def html_table(ar)
@working_array = ar
render("htmltable")
end
and here's the template rendered by the helper method:
#template used by the helper (htmltable):
<table>
<%for a in @working_array %>
<tr>
<%for element in a%>
<td><%=element%></td>
<%end%>
</tr>
<%end%>
</table>
That enables me to do this
<%=html_table(@list)%>
in my application template, and will display the array @list as html table.
The problem is that the working_array variable has to be used as
instance variable, possibly introducing naming collisions....
Is there a nice solution to this?
Or could a new render_* method be helpful, using all variables available
where it is called (even non instance variables)?
Thanks.
Raph
PS: not that I want to reopen the debate there was when comparing cgikit
and rails, but isn't the binding file preventing such naming collisions?
I'm trying to develop a Rails component to display a Ruby array as a
html table (which could evolve in something equivalent to CKHTMLTable
for cgikit).
I use a helper:
#Helper method that can be used in the main template:
def html_table(ar)
@working_array = ar
render("htmltable")
end
and here's the template rendered by the helper method:
#template used by the helper (htmltable):
<table>
<%for a in @working_array %>
<tr>
<%for element in a%>
<td><%=element%></td>
<%end%>
</tr>
<%end%>
</table>
That enables me to do this
<%=html_table(@list)%>
in my application template, and will display the array @list as html table.
The problem is that the working_array variable has to be used as
instance variable, possibly introducing naming collisions....
Is there a nice solution to this?
Or could a new render_* method be helpful, using all variables available
where it is called (even non instance variables)?
Thanks.
Raph
PS: not that I want to reopen the debate there was when comparing cgikit
and rails, but isn't the binding file preventing such naming collisions?