Dynamic form? Not really!


#1

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 %>

### First part - My 'manual' coded stuff <% odd_or_even = 0 %> ### 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 %> <% end %>
Field Contents
Company <% @companies.each do |company| %> <%= company.name %> <% end %>
<%= column.human_name %>: <%= text_field 'contact', column.name %>
<%= 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!


#2

Hi, Gerard,

On Sat, 31 Dec 2005 13:12:45 +0100
Gerard removed_email_address@domain.invalid wrote:

> <% @companies.each do |company| %> > > <%= company.name %> > > <% end %> >

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 T. removed_email_address@domain.invalid


#3

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 T. 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!


#4

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 O. tried to type
something
like:

You can also use the ‘cycle’ helper to do the table striping.

Do something like this…

">


“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!


#5

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


#6

You can also use the ‘cycle’ helper to do the table striping.

Do something like this…

">

#7

Kevin,

Thanx! That’ll be a nice cleanup in my views. Will take a look at that
:slight_smile:

And best wishes to you to!

(And ofcourse to all coders the world over!)

Grtz Gerard

On Sunday 01 January 2006 14:16, Kevin O. tried to type something
like:

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!