Strong parameters in Ruby -


i'm getting error message strong parameters. think it's rails 4 doesn't use attributes anymore. code toy.rb is:

class toy < activerecord::base    attr_accessible :name, :price, :vendor    validates :name, :presence => true    validates :price, :presence => true    validates :price, :numericality => true    validates :vendor, :presence => true  end  

how can change strong parameters?

edit: used different rb changed employees , have:

  class employee < activerecord::base params.require(:employee).permit(:first, :last, :salary, :salary, :ssn) validates  :first, :presence => true validates  :last, :presence => true validates  :salary, :presence => true validates  :salary, :numericality => true validates  :ssn, :presence => true  

end

it's still telling me "ndefined local variable or method `params' #"

the code need is

params.require(:toy).permit(:name, :price, :vendor) 

you put in controller. typically, create private method:

def create   toy.create(toy_params) end  private def toy_params   params.require(:toy).permit(:name, :price, :vendor) end 

see http://guides.rubyonrails.org/getting_started.html#saving-data-in-the-controller more information.

edit think might have misled original answer. code goes in controller, not model.


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -