thanks - got the auto-creation of nested models working!

Now I seem to be on the next challenge of getting decent validation
error messages show on the view with the nested models :)   Seems to
be somewhat discussed at
http://railscasts.com/episodes/75-complex-forms-part-3 but doesn't
seem to have a perfect solution.  Will keep digging.  If someone knows
of the latest/nicest way to nicely get detailed validation messages
appearing where it makes sense for a view with nested models I'd be
very interested  :)

thanks


On Sun, Nov 23, 2008 at 10:50 PM, Frederick Cheung
<[EMAIL PROTECTED]> wrote:
>
>
>
> Sent from my iPhone
>
> On 23 Nov 2008, at 12:38, "Greg Hauptmann" <[EMAIL PROTECTED]
>  > wrote:
>
>>
>> oh, got it Frederick,
>>
>> To be more self sufficient, how would I be able to confirm for myself
>> exactly what the Rails controller framework is looking for when it's
>> trying to create models out of the param's it gets (i.e. behind the
>> scenes before it gets to your code)?
>>
> Look at the code for update_attributes in activerecord
>
> Fred
>> If I had a way of confirming this then I could cement my understanding
>> of why Ryan's extra method made the difference (as an example).
>>
>> Do you have to pretty much look at Rails code to have derived this
>> understanding?   Like it's not even clear to me which rails tool is
>> being used to recursively build the models out of the params, as it
>> must get called in the rails code.  Hope this makes sense.
>>
>> Thanks again
>>
>>
>> On Sun, Nov 23, 2008 at 8:57 PM, Frederick Cheung
>> <[EMAIL PROTECTED]> wrote:
>>>
>>>
>>>
>>> On Nov 23, 7:21 am, "Greg Hauptmann" <[EMAIL PROTECTED]>
>>> wrote:
>>>> PS.  Actually I've just seen in this RailsCasts episode that Ryan
>>>> seems to have a nested model controller that does translate the
>>>> parent
>>>> & child model data from the form to parent model and its association
>>>> (child model).  Am I missing something Frederick re whether you may
>>>> have been wrong here?
>>>>
>>>>   Link =http://railscasts.com/episodes/73-complex-forms-part-1
>>>>
>>> That's one way of doing it, another is doing it in the controller (in
>>> your update & create methods as you suggested). But there isn't
>>> anything built in, if you look at Ryan's code he's added a magic
>>> accessor to his project model that massages an array of hashes into
>>> an
>>> array of task objects. You do need to  write that code and it has to
>>> go somewhere.
>>>
>>> Fred
>>>
>>>
>>>
>>>> On Sun, Nov 23, 2008 at 9:50 AM, Greg Hauptmann
>>>>
>>>> <[EMAIL PROTECTED]> wrote:
>>>>> thanks for responding Frederick:  So just to clarify you mean:
>>>>
>>>>> (a) I would have to do this in my controller in the "save" method
>>>>> right?
>>>>> (b) so anyone that anyone using Rails that has nested models in
>>>>> their
>>>>> views do have to do this too then?  i.e. extract work in the
>>>>> controller?  i.e. there's no ability in Rails 2.1 with nested
>>>>> models
>>>>> to have the params perfectly auto-populated the models (i.e. parent
>>>>> model and it's association models) out-of-the-box?
>>>>
>>>>> thanks again
>>>>
>>>>> On Sun, Nov 23, 2008 at 1:00 AM, Frederick Cheung
>>>>> <[EMAIL PROTECTED]> wrote:
>>>>
>>>>>> On Nov 22, 11:56 am, "Greg Hauptmann"
>>>>>> <[EMAIL PROTECTED]>
>>>>>> wrote:
>>>>>>> ok, re "I'm just trying to load a set of options which doesn't
>>>>>>> require
>>>>>>> tables (i.e. using tableless plugin)" I've got the View working
>>>>>>> now,
>>>>>>> however when I submit back I have an error as Rails tries to
>>>>>>> populate
>>>>>>> the association models.   Any ideas - it's like the parameter
>>>>>>> array/hash structure coming into Rails is fine, however when it
>>>>>>> tries
>>>>>>> to load the association data into the model for the
>>>>>>> associations it
>>>>>>> has a problem.
>>>>
>>>>>>> Is my model (graph_options.rb) correct?   Do I need to specify a
>>>>>>> specific "attr_accessible :lines" here?  Or should the "has_many
>>>>>>> :lines" be enough?
>>>>
>>>>>> attr_accessible is something completely different. The issue
>>>>>> here is
>>>>>> that all update_attributes does is for each key value pair it
>>>>>> calls
>>>>>> your_model.send("#{key}=", value). That's fine for attributes, but
>>>>>> that means that what it's passing to lines= is not an array of
>>>>>> Line
>>>>>> items, but an array of hashes.
>>>>>> In rails 2.1 you just have to extract that array of hashes, turn
>>>>>> it
>>>>>> into objects of the right type and then assign it to
>>>>>> your_object.lines. There was talk of changing this in rails 2.2
>>>>>> but I
>>>>>> can't remember what was done about it in the end.
>>>>
>>>>>> Fred
>>>>
>>>
>>
>> >
>
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to