I have a field 'status' that is using a state-machine plugin (rubyist-
aasm) to control state transitions. For instance, from 'new' you can
only go to 'apply' or 'ignore'.
I'd like to have a select field that's populated with only the
permissible states allowed based on the current value. I have
implemented this with a column override along the lines of
(simplified):
def status2_column(record)
y = [[record.status.to_s.humanize, record.status.to_s]]
r = record.aasm_events_for_current_state
y += r.
sort { |a,b| a.to_s <=> b.to_s }.
map { |x| [x.to_s.humanize, x] }
select_tag 'record[new_status]', options_for_select(y, ' ')
end
It would be preferable to use inplace_edit. Unfortunately, it always
reads the contents of the options field for that column which are
initialized once for the page. The actual code can be found at lib/
active_scaffold/actions/core.rb in the method render_field:
if params[:in_place_editing]
render :inline => "<%= active_scaffold_input_for
(active_scaffold_config.columns[params[:update_column].to_sym]) %>"
What I'd like to be able to do is say something like:
columns[:status].form_ui = :select
columns[:status].options = {:options
=> :status_value_list, :html_options => {}}
and then in my model:
def status_value_list
aasm_events_for_current_state.map { |e| [e.name,
e.name.to_s.humanize] } }
end
Before I go and patch AS to provide this, does anyone know if this
already exists? Or if there's a better way to skin this cat?
Thanks in advance.
--
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" 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/activescaffold?hl=en.