Answer the question
In order to leave comments, you need to log in
Can't assign a value to a Rails model field?
Friends I can’t understand at all what’s the matter, I’m just studying the rails, maybe the problem is on the surface ..
There is a model
class Liquid < ActiveRecord::Base
attr_accessor :name, :chemical
end
class CreateLiquids < ActiveRecord::Migration
def change
create_table :liquids do |t|
t.string :name
t.string :chemical
t.timestamps null: false
end
end
end
>> x.name=1
#<Liquid id: 8, name: nil, chemical: "1", created_at: "2015-10-18 08:58:31", updated_at: "2015-10-18 08:58:31">
Answer the question
In order to leave comments, you need to log in
This is an innovation in RoR version 4.
Read about strict parameters .
Created a migration renamed to nam - it worked, deleted the database file, migrations, did everything else
with the name field does not work
.. PS magic attr_accessor is not needed at all, who will have a similar problem
find in the controller in the "private" section a function called CONTROLLER NAME_params, see params.require(:CONTROLLER NAME).permit( _search here_ ) allowed params are listed in brackets, there should be ":name, :chemical", if not, then add . And remove "attr_accessor :name, :chemical" from the model
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question