Rails helper working with template

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?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,902
Latest member
Elena68X5

Latest Threads

Top