我已經通讀了幾個線程,目前還沒有。我正試圖將一種形式嵌套在另一種形式中。我得到了無法批量分配受保護的屬性錯誤。 \以嵌套的形式 - 無法批量分配受保護的屬性:
應用程序/控制器/ projects_controller.rb:46:在new' app/controllers/projects_controller.rb:46:in
打造」
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
project.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
這裏是錯誤...
ActiveModel :: MassAssignmentSecurity :: ErrorControl in ProjectsController#create
不能大規模指派保護的屬性: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
以供將來參考,它有助於包括確切的錯誤信息(所以我們可以看到什麼屬性是質量分配保護)。 –
你介意發佈你的表單嗎?我懷疑這可能是錯誤起源的地方。 –