I want to display the column ‘name’ after being found from the table mytest.
In the mytest.rb, I defined “attrib_accessor :name”;
In the procedure index under directory /controller/mytest_controller.rb,
def index
###[Ignore some code]
@mytesttbl=@user.find_by_id
### I am able to verify the tuples in @mytesttbl
end
In the /view/mytest/index.rhtml, I have code like
<div id="mytesttable"> <%= render(:partial =>"mytesttbl", :object => @mytesttbl)%> </div>
In the /view/mytest/_mytesttbl.html.erb. I have code like
<tr>
<td><%=mytestbl.name %></td>
<tr>
when I ran the above code, I have error on _mytesttbl.html.erb,
undefined method 'name ' for #<Array:0xb6c971cc>
Please help. Thanks,
I’m guessing that’s not your actual code since it wouldn’t actually work. Your
findis returning an array. You either want to loop through the array or, if you know it contains only one object (as in the case where you actually are finding by a unique id), you can just domytesttbl.firstto get the object out of it.