Tôi là một đường ray vì vậy dưới đây có lẽ là do thiếu hiểu biết tuy nhiên tôi đã tìm/đọc cả ngày và dường như không thể tìm ra giải pháp.Tạo một Rails 3 HABTM với Admin hoạt động ném một 'Không thể gán hàng loạt thuộc tính được bảo vệ:' lỗi
Tôi có hai mô hình - dự án và công nghệ:
dự án:
class Project < ActiveRecord::Base
attr_accessible description, :name
has_and_belongs_to_many :technologies, :join_table => :projects_technologies
end
Công nghệ:
class Technology < ActiveRecord::Base
attr_accessible :abbr, :description, :name
has_and_belongs_to_many :projects, :join_table => :projects_technologies
end
Create_Projects_Technologies di cư của tôi đã như sau:
class CreateProjectsTechnologies < ActiveRecord::Migration
def self.up
create_table :projects_technologies, :id => false do |t|
t.references :project
t.references :technology
end
add_index :projects_technologies, [:project_id, :technology_id]
add_index :projects_technologies, [:technology_id, :project_id]
end
def self.down
drop_table :projects_technologies
end
end
tôi sau đó sử dụng Active quản lý để tạo ra và mô hình chỉnh sửa dự án sử dụng các hình thức sau đây:
ActiveAdmin.register Project do
form do |f|
f.inputs "Project attributes" do
f.input :name
f.input :description
f.input :technologies, as: :check_boxes
end
f.buttons
end
end
Điều này cho thấy chính xác tất cả các công nghệ của tôi như là hộp kiểm Tuy nhiên ngay sau khi tôi gửi biểu mẫu tôi nhấn các lỗi sau đây mà tôi đã không thể vượt qua:
ActiveModel :: MassAssignmentSecurity :: lỗi trong Admin :: ProjectsController # cập nhật
Can't mass-assign protected attributes: technology_ids
Tất cả giúp đỡ rất nhiều đánh giá cao: D
Trong trường hợp bất cứ ai khác được tôi lỗi này đã đưa ra 'không thể hàng loạt assign bảo vệ attr_accessible: # {attrs.join} 'thay vì có' category_ids'. – ScottJShea