Removing mass-assignment from worker in rails

79 views Asked by At

I have a worker :

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

I don't have attr_accessible :name, :continent in city.rb. How should I remove this mass-assignment from the worker?

1

There are 1 answers

0
rxing On

check the link https://github.com/rails/strong_parameters about how to use strong parameter out of controller.

raw_parameters = { :email => "[email protected]", :name => "John", :admin => true }
parameters = ActionController::Parameters.new(raw_parameters)
user = User.create(parameters.permit(:name, :email))