Quick syntax question - newbie

Hi all, am writing a simple app that lets me pick a post type to go
under National or International.
the code bellow generates a drop-down from where I can pick the
options

<%= f.collection_select :postType_id, PostType.all(:order => "name ASC"), :id, :name %>

what would be the syntax for this if instead I wanted to have two
radio buttons
I search for some sample code but all i’ve found is only with hard
coded strings.

any idea how I can generate two radio buttons for:
O National
O International

?
any help will be greatly appreciated.
oli.

I think you’re looking for something like radio_group. Based on your
previous example, I would code it as:

<%= f.radio_group :postType_id, PostType.all(:order => "name ASC").map {|pt| [ pt.id, pt.name ] }

Chris, thanks.
but iam getting an this error after trying your code:

undefined method `radio_group’ for
#ActionView::Helpers::FormBuilder:0x1034d6800

am not sure if it is because this is a rails 3 app?
I googled this error but noting seemed helpful

<%= f.radio_group :postType_id, PostType.all(:order => “name ASC”).map
{|pt|
[ pt.id, pt.name ] }%>

any further help will be great.

oli.

it should be f.radio_button. more samples at

On Sun, Feb 20, 2011 at 10:29 PM, seor tower [email protected]
wrote:

{|pt| [ pt.id, pt.name ] }%>
On Sun, Feb 20, 2011 at 2:52 AM, Chris K. [email protected]wrote:

what would be the syntax for this if instead I wanted to have two
oli.


You received this message because you are subscribed to the Google G.
“Ruby on Rails: Talk” group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

Ah, yes. Sorry about that. The radio_group method isn’t a part of the
FormBuilder, so while you can still call it within the scope of the
form_for
block, you can’t call it the way I told you to.

You will need to call it similar to:

<%= form_for @post do |f| %>

<%= radio_group "post[postType_id]", PostType.all(:order => "name ASC").map {|pt| [ pt.id, pt.name ] }
... <% end -%>

This should work if you adjust the code to your particular situation,
but
post back if not.

On Mon, Feb 21, 2011 at 2:06 AM, Chris K. [email protected]
wrote:

Ah, yes. Sorry about that. The radio_group method isn’t a part of the
FormBuilder, so while you can still call it within the scope of the form_for
block, you can’t call it the way I told you to.

So there really is a radio_group helper? There’s nothing about it in the
api. Any links?

<% end -%>

On Sun, Feb 20, 2011 at 10:29 PM, seor tower [email protected]wrote:

<%= f.radio_group :postType_id, PostType.all(:order => “name ASC”).map

On Sun, Feb 20, 2011 at 5:21 AM, oliver torres [email protected]wrote:

any help will be greatly appreciated.
http://groups.google.com/group/rubyonrails-talk?hl=en.

To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en.

Er, yeah, that’s not going to work. It’s actually part of the Ruby
standard
lib as part of CGI::HtmlExtension, and now that I’m looking at it more
closely, it’s not compatible with Rails use. My bad. Rails only
supports
the radio_button helper, as Jim pointed out.