Radio buttons and other form fields

Hello I just started messing around with RoR yesterday. I have a simple little data entry app I’m learning on currently. I just set it up with the scaffold command and then used rake to make the db for me.

I have the fields all set up as “string” so they all by default from the scaffold use this same text boxes in the new.html.erb file

Code:

<% form_for(@beer) do |f| %>
  <p>
    <b>Name</b><br />

    <%= f.text_field :name %>
  </p>

My question is what is the do |f| actually doing. What is |f| referring to? Also how can I use a grouping of radio buttons to submit information as well as a select box with set options? (I want to have a “yes”, “no”, and “maybe”) radio group for one of my fields and I want a select box with the US States in it.

I have looked up the form stuff and all i could get it to do was display a radio button that did nothing when submitted. - I think this is probably my lack of understanding of ‘f.’

I know it has to be a simple little thing and I look like a real noob for asking - but hey, I am a noob! I’m really excited about learning more RoR as I go on - its really fun so far.

Thanks!

My question is what is the do |f| actually doing. What is |f| referring to? Also how can I use a grouping of radio buttons to submit information as well as a select box with set options? (I want to have a "yes", "no", and "maybe") radio group for one of my fields and I want a select box with the US States in it.

I have looked up the form stuff and all i could get it to do was display a radio button that did nothing when submitted. - I think this is probably my lack of understanding of 'f.'

f is a form builder (the docs for form_for should say something about that). In a nutshell it is an object that knows the the object you're manipulating is beer. You can create your own subclasses of Formbuilder that display things in particular ways.

Fred

Hi Truong,

This question is appropriate for rubyonrails-talk not rubyonrails-core.

Core is for discussing development of the Rails framework itself.

Cheers, Alan