> ar_lookup (field_name)
Thanks! That certainly looks more like Ruby, if only for less braces ;-)
I assume I can figger out how to make dollar notation work as well:
set :field => "customer", :val => [ "Customer", "find_by_name_and_city",
"${f:name}", "${f:city}" ]
So, I can surely use your code to build the custom form.
Next, I want to keep WorkItemController#update a bit generic, the I'd
need to know what form field names to expect. For that, I guess I need
to hardcode some name (in my case: I hardcoded the fieldname which
refers to the class that knows how to find the data, and which has
setters methods to set new values) -- unless someone has some better
solution for that as well!
Thanks,
Arjan.
-----Original Message-----
From: [email protected]
[mailto:[EMAIL PROTECTED] On Behalf Of John Mettraux
Sent: Monday, May 05, 2008 5:40 AM
To: [email protected]
Subject: [openwferu-users] Re: ruote-web: any thoughts on using custom
forms with external data?
On Sun, May 4, 2008 at 10:47 PM, Arjan van Bentem
<[EMAIL PROTECTED]> wrote:
>
> In my workflow application, based on ruote-web, I not only need to
> update workflow fields, but also some external data (which outlives
> the process when it is completed or canceled).
Hello Arjan,
I've tried to make it shorter :
---8<---
module OpenWFE::Extras
#
# reopening Workitem to add the ar_lookup method
#
class Workitem
#
# ar_lookup('customer')
#
# will expect the field (attribute) 'customer' to hold an array (or
a comma
# separated list) like [ 'Customer', 'find_by_hair_color', 'blue' ]
or
# "Customer, find_by_petname_and_city, Chester, Kualalumpur".
#
# Will return the corresponding active record[s].
#
# field_name is supposed to hold the name of a field in this
workitem.
#
def ar_lookup (field_name)
# TODO : add caching
fvalue = self.field field_name
fvalue = if fvalue.is_a?(Array)
fvalue
elsif fvalue.is_a?(String)
fvalue.split(",").collect { |e| e.strip }
else
nil
end
return nil unless fvalue
class_name, method_name, *args = fvalue
# args is an array
clazz = class_name.constantize
clazz.send method_name, args
end
end
end
--->8---
This version expects things like :
set :field => "customer", :val => [ "Customer",
"find_by_name_and_city", "Chester", "NY" ]
or
set :field => "pet", :value => "Pet, find_by_id, avb35"
It's a bit lighter than your version.
You should then be able to do :
---8<---
<% form_tag "/workitem/update/[EMAIL PROTECTED]" %>
<% fields_for :external_data, @workitem.ar_lookup('customer') do |f|
%>
a: <%= f.text_field :my_field_a %>
b: <%= f.text_field :my_field_b %>
c: <%= f.text_field :my_field_c %>
<% end %>
:
:
<% end %>
--->8---
In a fully RESTful world, we would do :
set :field => "external_stuff", :value =>
"http://dataserver/customer/xyz"
and PUT/GET/DELETE it. I'm thinking about it.
Hope this helps, cheers,
--
John Mettraux - http://jmettraux.wordpress.com
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"OpenWFEru users" 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/openwferu-users?hl=en
-~----------~----~----~----~------~----~------~--~---