开发者

use field that does not exsit in the model in the erb file

My model User contains only field hashed_password but not password and confirmed_password, which are requested to provide when registering. How should I write the view in this case? Following code will generate error Model User does not respond to password.

17:   </div>
18:   <div class="field">
19:     <%= f.label :password %><br />
20:     <%= f.text_field :p开发者_运维问答assword %>
21:   </div>


What you're looking for is called a virtual attribute. There's a good screencast on Railscasts that covers this: Railscasts - Virtual Attributes

Edit: In the case of your password and confirmed_password fields, you'll also want to look into filtering sensitive data from the request log as well using filter_parameter_logging.


But if it's fot authentication problem, you should probably use some sort of libs, like authlogic or devise, both these library would provide you with this virtual attributes.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜