Hi, I'm not sure if the following is a common issue in ActiveRecords
or in ActiveScaffold and how it manages models in subforms:

- Client has_many Routes (through "client_id" in "routes" table as usual).

- In Client model I need this validation:
    validates_presence_of :client_id, :if => Proc.new { |route| route.enabled }

- I need such validation because it's also possible to directly create
Routes in a separate way (without the need of creating a Client and a
Route(s) belonging ot it). In such case I need to ensure that the
route entry belongs to a Client just if the "enabled" field is checked
(in the Clientcontroller subform for Route such checkbox is hidden).

- If I want to create a Client with a Route (by filling the subform)
then I get this error:
    "client_id cannot be empty"

I think this error occurs because AS creates first the Route model
(just in memory, not yet in DB) for which, of course, there is not yet
a client_value, am I right? what is the workaround for this?

PS: If this is a pure ActiveRecord related question please just tell
it to me so I'll investigate in Rails/ActiveRecords forums.

Thanks a lot.

-- 
Iñaki Baz Castillo
<[email protected]>

-- 
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.

Reply via email to