formtastic - how to prepopulate a string input with a value

非 Y 不嫁゛ 提交于 2019-11-30 02:53:43
Justin French

Yup, you got the right answer all by yourself! Formtastic's rdoc is a mess, but we're working on it. Another option if you want this purely at a view level is to use the :input_html option, which gives you direct access to HTML attributes of the input tag:

f.input :email, :input_html => { :value => params[:email] }

sometimes the easiest things come to your mind by asking for them:

approach: do the job in the controller not the view!

if params[:email]
  @user = User.new(:email => params[:email])
else
  @user = User.new
end

sorry for bothering you!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!