4
formtastic & formtastic_cocoon을 사용하여 중첩 된 양식을 작성했습니다.동적 중첩 양식은 항상 여분의 빈 항목을 만듭니다. formtastic_coocoon을 사용합니다.
모두 하나의 예외를 제외하고 기존 양식에 동적으로 중첩 된 양식을 추가하는 것이 효과적입니다.
나는 사용자와 사용자가 있습니다. 내가 사용자를 생성하고, 항목을 추가 할 때 빈 항목이 항상 표시되는 이유
, 난 단지 내가 확실하지 않다
-User - Entry Test 1
해야
-User - Entry (empty) - Entry Test 1
와 끝까지 .
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
컨트롤러를 만들의 나된다
내 모델은
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
빈 항목
데이터베이스에 표시된다 (I이 오른쪽 컨트롤러 생각), 그래서 나는 생각하지 않는다 html.erb 파일에 문제가 있지만 도움이된다면 여기에 게시 할 수 있습니다.
참고로 모델을 변경. – nathanvda
그러나 formtastic에만 필요합니다. – Mindbreaker