我已经阅读了几个线程,到目前为止还没有。我正在尝试将一种形式嵌套在另一种形式中。我收到无法批量分配受保护的属性错误。\
app/controllers/projects_controller.rb:46:in new'
app/controllers/projects_controller.rb:46:in
create'
Projects_controller.rb
def create
@project = Project.new(params[:project])
respond_to do |format|
if @project.save
format.html { redirect_to @project, notice: 'Project was successfully created.' }
format.json { render json: @project, status: :created, location: @project }
else
format.html { render action: "new" }
format.json { render json: @project.errors, status: :unprocessable_entity }
end
end
end
项目.rb
WF::Application.routes.draw do
resources :line_items
resources :projects do
resources :line_items
end
devise_for :users
get 'about' => 'pages#about'
get 'Production' => 'projects#index'
root :to => 'pages#home'
end
这是错误...
ProjectsController#create 中的 ActiveModel::MassAssignmentSecurity::Error
无法批量分配受保护的属性:line_item
这是我的项目模型
class Project < ActiveRecord::Base
attr_accessible :quantity
# may be unnessary
attr_accessible :line_items_attributes
belongs_to :user
has_many :line_items
accepts_nested_attributes_for :line_items, :allow_destroy => true
end