ruby on rails - dynamic nested form always creates an extra blank entry - using formtastic_coocoon -
i'm using formtastic & formtastic_cocoon created nested form.
all seems working dynamically adding nested form existing form, 1 exception.
i have users , users have entries.
when create user, , add entry, end
-user - entry (empty) - entry test 1
i should have
-user - entry test 1
i'm not sure why blank entry showing up.
my models are
class user < activerecord::base validates :name, :presence => true has_attached_file :photo has_many :tasks, :dependent => :destroy accepts_nested_attributes_for :tasks, :allow_destroy => true end class task < activerecord::base attr_accessible :entry belongs_to :user end
my create controller (i think right controller)
def create @user = user.new(params[:user]) if @user.save flash[:notice] = "successfully created user." redirect_to @user else render :action => 'new' end end def create @task = task.new(params[:task]) if @task.save flash[:notice] = "successfully created task." redirect_to @task else render :action => 'new' end end
the empty entries showing in database, don't think problem html.erb files, can post here if help.
turns out may issue way formtastic_cocoon handles forms.
when looking @ html source, nested form in page, hidden.
i changed model
accepts_nested_attributes_for :tasks, :reject_if=> proc {|attributes| attributes[:entry].blank?}, :allow_destroy => true
Comments
Post a Comment