Hey
I have a page with a drop list. When the user selects an option in the
drop I call an action in the controller with ajax. Now, in the
controller, I gather some data from the db, but how do I present these
data in a nice way? I really need to make use of the html helpers, but
these clearly are not available in the controller. How do I output the
array that I have gathered?
My view page looks like this:
<%= javascript_include_tag "prototype" %>
<%
@genre
%>
<%= start_form_tag :action => ''index'' %>
<div id="genre_id_box">
<%=select(:genre, :id, @genres2)%>
</div>
<%= end_form_tag %>
<%= observe_field("genre[id]",
:frequency => 0.25,
:update => "identities_box",
:url => { :action => :view_genre },
:with => "''genre_id=''+value") %>
<h1>Identiteter</h1>
<div id="identities_box">
<table>
<tr>
<td>Namn</td>
<td>Beskrivning</td>
<td>Bild</td>
</tr>
<% for identity in @identities %>
<tr>
<td><%= link_to (h identity.name), :action =>
"view_identity", :id
=> identity %></td>
<td><%=h identity.description %></td>
<td><img src="<%=h identity.imagepath %>"
/></td>
</tr>
<% end %>
</table>
</div>
<br />
__________________________________
In the controller I have the action view_genre defined, called when user
selects an option in the drop list:
def view_genre()
@identities =
Identity.available_identities(params[''genre_id''])
#
#Here I would like to output the array with identities in a
table just like I did when the view loaded in the users browser. Problem
is, I dont know how to do it and still make use of the handy html
helpers.
#
end
______________________
This brings me to the question about DRY (dont repeat yourself). If I in
the action "view_genre" in the controller also writes how the table
should be rendered, then I have the table definition in two places, both
controller and view, that cant be right.
I guess I have to pass the array to the view in som way when the ajax
call is coming in to the controller, and then let the view create the
updated table... but, I dont know how. Please, I need some help here.
--
Posted via http://www.ruby-forum.com/.