I have a Model called Status, its handling a table with two columns Stat and Colour.
Since these columns are also Model methods I would expect the following to work without an error
@a = Status.where(:stat => "Operational")
@a.colour = "Green"
However when I call @a.colour I receive an error stating that the method ‘colour=’ does not exist.
I am calling @a.colour from within seeds. This is just a model, it does not have a controller with it.
What am i doing wrong?
–Edit–
Model
class Status < ActiveRecord::Base
end
schema
create_table "statuses", :force => true do |t|
t.string "stat"
t.string "colour"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
Is this what you requested? I did not fully understand the request,
Kind Regards
I suppose
Status.where()returns more than one record. So you are trying to call thecolor=method on an array which obviously does not exist!So you need to iterate trough all found records, using
For more information check the Rails ActiveRcord Query Interface guide, it tells you: