This works only if one record is matched, but there are two or more
records it only prints first of the record. Please help me, i'm just
beginner in rails
<% for column in Info.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<tr>
<% for column in Info.content_columns %>
<td> <%=h @info.send(column.name) %></td>
<% end %>
This works only if one record is matched, but there are two or more
records it only prints first of the record. Please help me, i'm just
beginner in rails
that's what find_by_xxx does, it boils down to a find :first.
find_all_by_xxx is the find :all equivalent.
Sorry it doesn't work still it prints the first record. Is there a
problem with my view file => list2.rhtml ?
I think i must write another for block for loop in array
<% for ..............%> ==>>> like this but i really dont know what
should i write
<% for column in Info.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<tr>
<% for column in Info.content_columns %>
<td> <%=h @info.send(column.name) %></td>
<% end %>
Then in your list2 action load the corresponding infos ( params[:ids]
will be the list of ids) and iterate over them in your view.
Would be easier if you didn't have the redirect in the middle.
<% for column in Info.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<tr>
<% for column in Info.content_columns %>
<td> <%=h @info.send(column.name) %></td>
<% end %>
Offff. I can't believe how could be this thing so hard with rails.
<% for column in Info.content_columns %>
<th><%= column.human_name %></th>
<% end %>
</tr>
<tr>
<% for column in Info.content_columns %>
<td> <%=h @info.send(column.name) %></td>
<% end %>
Offff. I can't believe how could be this thing so hard with rails.
Info.find will return an array if you give it an array of ids. You
need to iterate over that collection. Any entry level rails tutorial
should cover this sort of thing.
Fred has (as usual) offered very good help. I believe that your
problem is that you have poorly modeled routes. A 'list' type of
action is generally a collection method, not a member method, and thus
has no id associated with it.
It also makes little sense to respond to one request by fetching the
necessary information and _always_ redirecting. Perhaps you should be
using:
render :action=>'list2'
instead. That way you'd be using the data that you've already
gathered (@info) and simply rendering it out using the template from
another action.
Long story short, it's not Rails that's the problem, it's having too
loose a grasp on its principles.