matt7
(matt)
1
I created a scaffolded project, and there is a line that I don't
understand fully, even with the RDoc info
in my listing.rhtml:
<% for listing in @listings %>
<td><%=h listing.send(column.name) %></td>
What is the meaning of send(column.name) ?
The RDoc says that it should "invoke the method name identified by
symbol ..."
But in this case, column.name isn't a method name (that I'm aware of),
so what is it calling or doing?
Thanks
Matt
hi,
@listing I suppose is a collection of listing where you listing represents a model in your database.
assuming listing database table listings have columns id,name
your model will have methods name=(val) and (#not exactly like this but something like this)
“name” which will set and get the value ActiveRecord Base class will do this dynamically for you.
listing.name will get value for you
listing.name=“xyz” will set value for you
column.name above will fetch “name” for you
then listing.send(column.name)=>listing.send(“name”)=>
listing.name
which will return the value for it.
hope this helps.
regards
gaurav
matt7
(matt)
3
Ugh... My cut/paste in the original post left out a crucial line, and
after thinking about it, I think I know what it does ....
<% for listing in @listings %>
<tr>
<% for column in Listing.content_columns %>
<td><%=h listing.send(column.name) %></td>
If I understand things right, for every listing, it is grabbing the
contents of each column, for each row, and placing the data into a table
row.
hmmmm ... sorry for the wasted bandwidth and thanks for the help.
Matt