github에서 중첩 된 양식을 배우려고 시도하는 합금 - 복합 - 양식 예제를 따르고 있으며이 작업을 수행 할 수 없습니다. http://github.com/alloy/complex-form-examplesNoMethodError in projectss # new
NoMethodError in Projects#new
Showing app/views/projects/_form.html.erb where line #13 raised:
You have a nil object when you didn't expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.new_record?
Extracted source (around line #13):
10: </p>
11:
12: <p>
13: <% project_form.fields_for :author do |author_form| %>
14: <%= author_form.label :name, "Author name:" %>
15: <%= author_form.text_field :name %>
16:
Trace of template inclusion: app/views/projects/new.html.erb
class Comment < ActiveRecord::Base
belongs_to :post
end
class Post < ActiveRecord::Base
validates_presence_of :name, :title
validates_length_of :title, :minimum => 5
has_many :comments
has_many :tags
accepts_nested_attributes_for :tags, :allow_destroy => :true ,
:reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } }
end
class Tag < ActiveRecord::Base
belongs_to :post
end
누구나 어떤 조언을? 나는 하루 종일 작동하도록 중첩 된 양식을 얻으려고 노력했지만 실패했습니다.
projectsController
class ProjectsController < ApplicationController
def index
@projects = Project.find(:all)
end
def show
@project = Project.find(params[:id])
end
def new
@project = Project.new
@project.tasks.build
@project.tags.build
end
def create
@project = Project.new(params[:project])
if @project.save
flash[:notice] = "Successfully created project."
redirect_to @project
else
render :action => 'new'
end
end
def edit
@project = Project.find(params[:id])
# add an extra new record for debugging purposes
@project.tasks.build
@project.tags.build
end
def update
@project = Project.find(params[:id])
@project.attributes = params[:project]
if @project.save
flash[:notice] = "Successfully updated project."
redirect_to @project
else
render :action => 'edit'
end
end
def destroy
@project = Project.find(params[:id])
@project.destroy
flash[:notice] = "Successfully destroyed project."
redirect_to projects_url
end
end
ProjectsController에있는 것을 보여줄 수 있습니까? – agregoire
ProjectsController – Jason