My app has three models:
Thread (has_many :thread_apps)
ThreadApp (belongs_to :thread, has_many :forms, :as => :appable)
Form (belongs_to :app)
ThreadApp Fields: thread_id, form_id, appable_id, appable_type
What I want to be able to do is when creating a form, ensure that a ThreadApp record is also created to make the association:
Here is what I have:
class FormsController < ApplicationController
def create
@thread = Thread.find(params[:thread_id])
@thread_app = @thread.thread_apps.new
@form = @thread_app.forms.build(params[:form].merge(:user_id => current_user.id))
@form.save
....
This is saving the form nicely, but the thread_app associated is not being made? Any ideas why?
Thank you
callings
model.savedoes not save associations unless you tell it toyou can set autosave
or call save on it in the controller
or you can take it out of the controller entirely
and do this with a callback
or after_create, _before_validation_on_create, or any other call back would work
—UPDATE—
this might make a difference using create inse=tead of new, and
appablesthat you specified as ‘as’