The issue isn't about mis-configuring. I could help you with ways around this but all of them are "hacks"
The issue is that active scaffold creates the children with out knowing what their parent is. When you create it's only creating the parent from the parameters that you ask for in the form. One way you could solve this is that every time you create a child have java script add to a hidden tag that contains the id's of all the children and then when you create the object the associate the child records with the parent. Now you also have an issue though, because if someone decides to cancel the course those child records are still hanging around in the data base. On Fri, Feb 13, 2009 at 3:44 PM, [email protected] < [email protected]> wrote: > > Hi Kenny, > > That is exactly what happens. I have no clue how to solve this. I > assume that I am not the only person to use ActiveScaffold that way. > Therefore, I guess it is just something I haven't configured or > misconfigured. > I searched the documentation again and re-read the example with that > before_create_save method (on the embedded scaffold page). > I tried to implement it in my controller like this: > > class InstanceController < ApplicationController > before_filter :load_course > > # This is needed to prevent an exception when the sub-form doesn't > validate > protect_from_forgery :only => [:create, :update, :delete] > > active_scaffold :instance do |config| > config.actions.exclude :show, :search > config.create.label = "Add a new date for this course" > config.create.link.label = "Add a date" > > # Columns to display in the sub-table > config.columns = [:course_start, :course_end] > end > > def load_course > begin > @parentcourse = Course.find(active_scaffold_session_storage > [:constraints][:course_id]) > rescue > @parentcourse = Course.new > end > end > > def before_create_save(record) > record.course_id = @parentcourse.id if @parentcourse.id > end > > end > > > But that didn't change anything. > Maybe the solution is here > http://code.google.com/p/habtm-with-deferred-save > but frankly speaking, I am not keen to install it and further tweak my > application with a potentially unstable patch. > > Of course, I could just use AS for all my controllers but then my > customised views would be useless. > Could it just be that AS can't do what I want to do? > > Thanks for your advices. > > Christian. > > On Feb 13, 3:28 pm, Kenny Ortmann <[email protected]> wrote: > > So to make sure I understand your issue, when you create the instances > > through active scaffold and you do not yet have a Course it does not know > > what course_id to set on the instance. You fixed this issue by allowing > an > > instance to be created with out a course_id. So now your issue is that > you > > create instances and they show up on your course page, but when you > create > > the Course these instances are not associated with the course. > > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
