ruby - 虚拟属性的 属性名= 方法不执行
巴扎黑
巴扎黑 2017-04-24 09:09:50
0
3
709

user.rb 定义了 password 虚拟属性

user.html.erb 定义了虚拟属性表单

然而输出了一下 password= 那个方法没有执行....23333

请指教

巴扎黑
巴扎黑

reply all(3)
巴扎黑

Because ror 4.2 is used, the correct way is to add your virtual attributes to :permit(:virtual attribute name)

阿神

I haven’t used erb much, but are you sure that this method will be called in the template? password= I am used to using
callbacks for this kind of needs...before_create

Also, leave this kind of thing to professionals.

刘奇

Ruby on Rails does not need to write attr_accessor directly.

But you need to use strong-parameters. Refer to the following writing method and add password to the whitelist:
http://edgeguides.rubyonrails.org/action_controller_overview.html#stro...

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!