我使用uuid_id gem 为我的应用程序中的各种模型生成 UUID(Rails 3.2.5 和 Ruby 1.9.3p194)。我正确地遵循了这里给出的步骤
创建标记为 的模型时出现此错误uuid_it
。如果我uuid_it
从模型中删除呼叫,它工作正常
这是日志的快照
SQL (2.1ms) INSERT INTO "applications" ("created_at", "description", "name", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id" [["created_at", Mon, 03 Sep 2012 10:17:59 UTC +00:00], ["description", "data mining"], ["name", "BlueBerry"], ["updated_at", Mon, 03 Sep 2012 10:17:59 UTC +00:00]]
Uuid Load (1.2ms) SELECT "uuids".* FROM "uuids" WHERE "uuids"."uuidable_id" = 5 AND "uuids"."uuidable_type" = 'Application' LIMIT 1
(0.2ms) ROLLBACK
Completed 500 Internal Server Error in 81ms
ActiveModel::MassAssignmentSecurity::Error (Can't mass-assign protected attributes: uuid):
app/controllers/applications_controller.rb:13:in `create'
第 13 行在哪里application.create
编辑
应用程序/控制器/应用程序.rb
class ApplicationsController < ApplicationController
# some code here
def create
@application = Application.new(params[:application])
@application.creator = current_user
@application.organization = current_organization
if @application.save
redirect_to @application, notice: "Successfully created application."
else
render action: 'new'
end
end
# few lines here
end