Topic: Forms 2: The Sequel

Thanks to all the help I received back in Forms 1, my form now looks like this (this works):

[code:ruby]
<% form_for :tile, :url => {:action => "save_tile", :id => @location, :tile_id => @tile} do |form| %>
    <p>Image: <%= form.select(:imageURL, %w{ Wall.gif Passage.gif Chest.gif DeadEnd.gif })%></p>
    <p>State: <%= form.text_field(:state) %></p>
    <p><%= submit_tag "Save" %></p>
<% end %> [/code]

I would like to upgrade this to make it simpler and more human-friendly.

Specifically, I'd like radio buttons, with each choice displaying its associated image, and setting the tile's associated state. (In case it's not clear - the state value is where I'm keeping the knowledge of how a passage, or a chest, or whatever, is supposed to operate. If there's a better way to do this, I'd like to know it.)

My first try at doing this:
[code:ruby]
<% form_for :tile, :url => {:action => "save_tile", :id => @location, :tile_id => @tile} do |form| %>

    <p><%= form.radio_button(:imageURL, "Wall.gif", :state => 0) %>
    <p><%= form.radio_button(:imageURL, "Passage.gif", :state => 2)%>

    <p><%= submit_tag "Save" %></p>
   
<% end %> [/code]

Produced two radio buttons, all right. Two unlabeled radio buttons, which did change the imageURL value, but not the state. What should I do instead?

God is a storyteller.

Re: Forms 2: The Sequel

What's the html that you'd like these radio buttons to have?

Re: Forms 2: The Sequel

I.. um... don't.. really.... know.

I'd like the radio buttons to display images as their selection criteria. And I'd like the choice of image to automaticallly pass a corresponding 'state' value.

Can that even be done?

God is a storyteller.

Re: Forms 2: The Sequel

I solved it!

Actually, I decided to eschew forms entirely.

I realized that since I wanted the tile to have a certain set of image, state, and filler_id, and not be able to deviate from predefined sets, (since it wouldn't make sense to have the image look empty but the program think it was full), I was better off putting those attributes in a separate model, and saying that :tile belongs_to :square.

So now I've got two sets of images - the editable grid of Tiles that goes in the Location, and a row of possible Squares that I can assign to the Tiles. It works quite nicely.

Next step: Populating the Tiles with Monsters!

God is a storyteller.