When using radio_button, how do you get some text in the label? For instance, the API ref gives the following example: radio_button("post", "category", "rails") <input type="radio" id="post_category" name="post[category] value="rails" checked="checked" /> My own use of radio_button is not showing any label. This might be because the data is numeric, not a string. Anyway, continuing the above example, how would I get the following output? <input type="radio" id="post_category" name="post[category] value="rails" checked="checked"> The Rails Category -- YEAH! </input> The problem I have is trying to map text strings for importance ("High", "Medium", "Low") to integers (3, 2, 1). Any clues? Gavin
On Apr 5, 2005 9:38 PM, Gavin Sinclair <gsinclair-81uBx+iSpXA0n/F98K4Iww@public.gmane.org> wrote:> When using radio_button, how do you get some text in the label? For > instance, the API ref gives the following example: > > radio_button("post", "category", "rails") > <input type="radio" id="post_category" name="post[category] value="rails" checked="checked" /> > > My own use of radio_button is not showing any label. This might be > because the data is numeric, not a string. Anyway, continuing the > above example, how would I get the following output? > > <input type="radio" id="post_category" name="post[category] value="rails" checked="checked"> > The Rails Category -- YEAH! > </input>Use the label tag to associate text with an input tag. <label for="post_category">Rails Category</label> <input type="radio" id="post_category" name="post[category] value="rails" checked="checked" />> The problem I have is trying to map text strings for importance > ("High", "Medium", "Low") to integers (3, 2, 1).This probably isn''t the Rails Way (tm), but I took a cue from my c# experience and its enums. This example is from my comic book application. class CreatorJob @@values = { 1=>''writer'', 2=>''penciller'', 3=>''inker'', 4=>''colorist'', 5=>''letterer''} def self.values @@values end end # creates attributes with the numbers as values CreatorJob.values.each do |k,v| CreatorJob.module_eval %Q{def self.#{v}\n #{k}\n end} end Now, I use this like so: @model.job = CreatorJob.writer # sets it to 1 Here''s an example: http://dev.comiclog.com/file/trunk/lib/creator_job.rb If there''s a better way, I''m all ears. -- rick http://techno-weenie.net
On Wednesday, April 6, 2005, 2:36:39 PM, Rick wrote:> Use the label tag to associate text with an input tag.> <label for="post_category">Rails Category</label> > <input type="radio" id="post_category" name="post[category] > value="rails" checked="checked" />That provides a label for the _group_ of radio buttons. I want a (different) label for _each_ radio button.>> The problem I have is trying to map text strings for importance >> ("High", "Medium", "Low") to integers (3, 2, 1).So for this mapping, I want the following abbreviated HTML (I think). <label for="importance">Importance</label> <input type="radio" id="post_category" name="post[category] value="1">high</input> <input type="radio" id="post_category" name="post[category] value="2">medium</input> <input type="radio" id="post_category" name="post[category] value="3">low</input> At the moment, I _am_ using the <label> tag, but the radio buttons appear by themselves. They _are_ responsive, in that I can use them to affect the model, but a user would have no idea which one to select.> This probably isn''t the Rails Way (tm), but I took a cue from my c# > experience and its enums. This example is from my comic book > application.> class CreatorJob > @@values = { > 1=>''writer'', > 2=>''penciller'', > 3=>''inker'', > 4=>''colorist'', > 5=>''letterer''} > def self.values > @@values > end > end> # creates attributes with the numbers as values > CreatorJob.values.each do |k,v| > CreatorJob.module_eval %Q{def self.#{v}\n #{k}\n end} > end> Now, I use this like so:> @model.job = CreatorJob.writer # sets it to 1> Here''s an example: > http://dev.comiclog.com/file/trunk/lib/creator_job.rb> If there''s a better way, I''m all ears.You could abbreviate it: class CreatorJob {1=>''writer'', 2=>''penciller'', ...}.each do |k,v| module_eval %Q{...} end end Do you happen to use it with radio buttons? :) Gavin
On Wednesday, April 6, 2005, 6:59:59 PM, David wrote:> Input items do not contain anything; you can''t have a </input> tag> Where I have something like this, I have just:> <input type="radio" id="post_category" name="post[category] value="1">high> with no </input>Thanks a lot. Makes sense, I guess. Now I''m using the radio_button method successfully, so I''m happy. Gavin
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Gavin Sinclair wrote: | <input type="radio" id="post_category" name="post[category] value="1">high</input> Input items do not contain anything; you can''t have a </input> tag Where I have something like this, I have just: <input type="radio" id="post_category" name="post[category] value="1">high with no </input> another approach would be to use some css: <dl> ~ <dt><input type="radio" ... ></dt> ~ <dd>high</dd> </dl> and then do a float left or float right to move one of them over. - -- David Morton Maia Mailguard server side anti-spam/anti-virus solution: http://www.maiamailguard.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.5 (GNU/Linux) Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org iD8DBQFCU6UPSIxC85HZHLMRAjpBAJ4qMe3c0CCKrOOdJMysV8MpA8ZAzQCeKhtK F1Nc1isHsP4890EPrq63t/k=S+uC -----END PGP SIGNATURE-----