2012-07-10 34 views
0

我無法創建新的api_user。每次我嘗試創建它,我得到ActiveModel :: MassAssignmentSecurity :: ApiUsersController中的錯誤#create

Can't mass-assign protected attributes: utf8, authenticity_token, api_user, commit, action, controller 

這裏是我的模型api_user.rb

class ApiUser < ActiveRecord::Base 
attr_accessible :api_key, :count, :email, :name, :organization 
end 

控制器api_users_controller.rb

class ApiUsersController < ApplicationController 
#skip_before_filter :verify_authenticity_token 

def new 
    @api_user = ApiUser.new 
end 

def create 
    @api_user=ApiUser.create(params) 
    render :text=>"#{@api_user.id}" 
end 

def destroy 
    @api_user=ApiUser.find(params[:id]) 
    @api_user.destroy 
    render :text=>"Deleted successfully" 
end 
end 

我使用Ruby 1.9.2和Rails 3.2.3

回答

1

爲了創建ApiUser,您應該只使用正確的參數:

@api_user=ApiUser.create(params[:api_user]) 

不是所有的params哈希

+0

,幫助的感謝! – 2012-07-10 11:14:43

相關問題