Radio buttons and whatnot

Hey guys,

I got a statuses model which holds all my applications statuses, they
are differentiated by their status type.

In my application I have some invoices that I want to be able to set
their invoice.status using radio buttons (which are created in my view
from the statuses table).

Does anyone have any idea on how to achieve this, as there appears to be
little help available online for such things.

thanks a bunch

dave

Dave S. wrote:

Hey guys,

I got a statuses model which holds all my applications statuses, they
are differentiated by their status type.

In my application I have some invoices that I want to be able to set
their invoice.status using radio buttons (which are created in my view
from the statuses table).

Does anyone have any idea on how to achieve this, as there appears to be
little help available online for such things.

thanks a bunch

dave

nay ideas?

Seek out the API docs grasshopper…

From http://api.rubyonrails.org/

Module
ActionView::Helpers::FormHelper

radio_button(object_name, method, tag_value, options = {})

Returns a radio button tag for accessing a specified attribute
(identified by method) on an object assigned to the template (identified
by object). If the current value of method is tag_value the radio button
will be checked. Additional options on the input tag can be passed as a
hash with options.

Let’s say that @post.category returns “rails”:
radio_button(“post”, “category”, “rails”)
radio_button(“post”, “category”, “java”)

Or
radio_button(“user”, “receive_newsletter”, “yes”)
radio_button(“user”, “receive_newsletter”, “no”)

Can’t resist adding this gratuitous and unsolicited advice:

If an application can only have one status at a time, resist any urge
you might feel to store status in a series of boolean fields in
applications. Instead, have your controller just store the id of the
selected status in application.status_id.

That way you don’t have to worry that an application might wind up with

1 of those booleans checked at a time, you should be able to add/rename
statuses at will, etc.

Ar Chron wrote:

In your case, have the appropriate controller read in the statuses info
and hand that to the view…

@statuses = Status.find(:all, :order => ‘something’)

Then the view (or a partial) can do something like:

@statuses.each do |this_status|
radio_button(“application”, “status”, this_status.value)
end

or sumfink like that…

brill… i understand.

what i have done it put it in a partial in my page form.

I have a projects page with a list of project_tasks and I want to use
the same code in this page and have the status in the form of a radio
button for each task, so I have put the code into a partial in projects
view.

This is my partial.

<% Status.find_all_by_type(“Project”).each do |s|%>
<%= f.radio_button :status_id, s.id %>
<%= f.label :status_id, s.name %>
<% end %>

I am trying to make a link to the partial on the projects show.html.erb
page. I know the code below this will not work, but am trying to adapt
it to take the task instead of the project form object.

<%= render :partial => "statuses", :locals => { :f => f } %>

obviously my partial here will be expecting a project form object… any
clues?

<% form_for(@project) do |f| %>
<% for task in @project_tasks %>
<%= render :partial => “statuses”, :locals => { :f => f } %>
<% end %>
<% end %>

I want it to take the task object instead

any ideas?

In your case, have the appropriate controller read in the statuses info
and hand that to the view…

@statuses = Status.find(:all, :order => ‘something’)

Then the view (or a partial) can do something like:

@statuses.each do |this_status|
radio_button(“application”, “status”, this_status.value)
end

or sumfink like that…

Dave S. wrote:

<% form_for(@project) do |f| %>
<% for task in @project_tasks %>
<%= render :partial => “statuses”, :locals => { :f => f } %>
<% end %>
<% end %>

I want it to take the task object instead

any ideas?

bump

dont worry i fixed it. just moved the form into the loop cheers guys

<% form_for(@project) do |f| %>
<% for task in @project_tasks %>
<%= render :partial => “statuses”, :locals => { :f => f } %>
<% end %>
<% end %>

I want it to take the task object instead

any ideas?

bump