从rails中的worker中删除mass-assignment

时间:2015-06-17 23:49:34

标签: ruby-on-rails security ruby-on-rails-4 mass-assignment

我有一个工人:

module A
 class B
  @queue = :a_b
  def self.perform(*args)
    ...............
    city = City.where(:country_id => 1).first
    city.update_attributes(name: "Delhi", continent: "Asia") //mass-assignment here
    ...............
  end
 end
end

attr_accessible :name, :continent中没有city.rb。我该如何从工人那里删除这个批量分配?

1 个答案:

答案 0 :(得分:1)

检查链接https://github.com/rails/strong_parameters,了解如何从控制器中使用强参数。

raw_parameters = { :email => "john@example.com", :name => "John", :admin => true }
parameters = ActionController::Parameters.new(raw_parameters)
user = User.create(parameters.permit(:name, :email))