hi i have a belongs to set up between 2 models. Exhibition belongs to license_instance. The model code is fine because i use it in a number of other places on the site. One thing i would like to do is create the 2 models at the same time in one form. I have been usinghttp://railsforum.com/viewtopic.php?id=717but i am running in to trouble when i try and save.
The folloing is my controller code
##################################################### def create #create the new @exhibition model @exhibition = Exhibition.new(params[:details]) @exhibition.user = current_user @exhibition.listing_status = ListingStatus.find_by_id(2) @exhibition.image_id = -1
#check if license needs to be created for this model. if @exhibition.description != "" @licenseinstance = @exhibition.build_license_instance(params[:newdetails]) @licenseinstance.format = "Text" @licenseinstance.license_jurisdiction_id = 1 end
#checks if the is free button has been ticked. if so sets this to the price. if params[:otherdetails][:isfree] == "yes" @exhibition.admission_price = "Free" end
#saves the whole exhibition with the license details included. if @exhibition.save flash[:notice] = "Exhibition details inserted" session[:exhibition] = @exhibition redirect_to :controller => "/listing/edit", :action => "index" else flash[:notice] = "Error inserting Exhibition and creating license" @license_types = LicenseType.find(:all) end end #####################################################
everything works but the license instance does not get saved. What am i doing wrong??? Do i have to call the .save method on the license object? I was under the understanding that the .build_license_instance method would do this when the .save method on the exhibition is called.
Where does the license_instance actually get connected with the exhibition? What exactly is in the build_license_instance method?
Best,
-r