Hi guru's out there,
Im happilly coding my first rails app, and all goes well. I find myself
manually coding in a particular field all the time (company_id), that relates
the contact to a company. The total coding of this form seems somewhat much.
Could somebody tell me what Rails power I'm possibly missing and stuborn as I
am trying to do myself?
I was wondering if the first part of the form can simply be put in the loop
somehow and still be a dropdownlist. So if anybody wants to shoot, here's the
form code:
<%= start_form_tag :action => 'update_contact', :id => @contact %>
<table border="0" cellpadding="3"
cellpadding="0">
<tr>
<th>Field</th><th>Contents</th>
</tr>
### First part - My 'manual' coded stuff
<% odd_or_even = 0 %>
<tr class="ListLine<%= odd_or_even
%>"><td>Company</td>
<td>
<select name="contact[company_id]">
<% @companies.each do |company| %>
<option value="<%= company.id %>">
<%= company.name %>
</option>
<% end %>
</select>
</td></tr>
### The cool dynamic part that shows the rest
<%
odd_or_even = 0
for column in Contact.content_columns
odd_or_even = 1 - odd_or_even
%>
<tr class="ListLine<%= odd_or_even %>">
<td><%= column.human_name %>:</td>
<td><%= text_field 'contact', column.name %></td>
</tr>
<% end %>
</table>
<input type="submit" value="Save" />
<%= end_form_tag %>
Thanx a lot guys!
Regards,
Gerard.
--
"Who cares if it doesn't do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."
My $Grtz =~ Gerard;
~
:wq!
Hi, Gerard, On Sat, 31 Dec 2005 13:12:45 +0100 Gerard <mailing@gp-net.nl> wrote: <select name="contact[company_id]"> > <% @companies.each do |company| %> > <option value="<%= company.id %>"> > <%= company.name %> > </option> > <% end %> > </select> you can replace above with following: ( if @companies are extracted from Company class (companies table) ) <%= @companies = Company.find(:all) collection_select(:contact, :company_id, @companies, :id, :name ) %> -- Hiroshi Takagi <gollum@hi-net.zaq.ne.jp>
Hiroshi, Great thanx. That worked. But my more pressing question: Is it necessary to have the dropdownlist generated seperately from the full field generation loop? Regards, Gerard. On Saturday 31 December 2005 13:39, Hiroshi Takagi tried to type something like: > <%= @companies = Company.find(:all) > ? ? collection_select(:contact, :company_id, @companies, > ? ? ? ? ? ? ? ? ? ? ? :id, :name ) > %> -- "Who cares if it doesn't do anything? It was made with our new Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." My $Grtz =~ Gerard; ~ :wq!
You can also use the 'cycle' helper to do the table striping.
Do something like this...
<tr class="ListLine<%= cycle("0","1")
%>">
--
Posted via http://www.ruby-forum.com/.
Kevin,
I did not digest the helper chapter yet in the Agile webdev book, but I asume
you mean create a shareable function called cycle, and remove the code from
the view?
Grtz n Thanx
Gerard.
On Saturday 31 December 2005 14:23, Kevin Olbrich tried to type something
like:
> You can also use the 'cycle' helper to do the table striping.
>
> Do something like this...
>
> <tr class="ListLine<%= cycle("0","1")
%>">
--
"Who cares if it doesn't do anything? It was made with our new
Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..."
My $Grtz =~ Gerard;
~
:wq!
Gerard wrote: > Kevin, > > I did not digest the helper chapter yet in the Agile webdev book, but I > asume > you mean create a shareable function called cycle, and remove the code > from > the view? > > Grtz n Thanx > > Gerard. 'cycle' is a predefined helper for doing table striping. See http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M000430 -- Posted via http://www.ruby-forum.com/.
Kevin, Thanx! That'll be a nice cleanup in my views. Will take a look at that .. :-) And best wishes to you to! (And ofcourse to all coders the world over!) Grtz Gerard On Sunday 01 January 2006 14:16, Kevin Olbrich tried to type something like: > Gerard wrote: > > Kevin, > > > > I did not digest the helper chapter yet in the Agile webdev book, but I > > asume > > you mean create a shareable function called cycle, and remove the code > > from > > the view? > > > > Grtz n Thanx > > > > Gerard. > > 'cycle' is a predefined helper for doing table striping. > > See > http://api.rubyonrails.com/classes/ActionView/Helpers/TextHelper.html#M0004 >30 -- "Who cares if it doesn't do anything? It was made with our new Triple-Iso-Bifurcated-Krypton-Gate-MOS process ..." My $Grtz =~ Gerard; ~ :wq!