Rails Simple_Form服务器端验证丢失的URL参数 [英] Rails simple_form server side validations lost URL params
本文介绍了Rails Simple_Form服务器端验证丢失的URL参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
此代码运行正常
<%= f.input :first_name, :label => 'First Name', :input_html => { :value => params['first'] } %>
使用URL
http://localhost:3000/charities/new?first=Bob
输出此HTML的
<input class="string required" id="charity_first_name" name="charity[first_name]" size="50" type="text" value="Bob" />
但是,如果表单服务器端验证失败,页面将重新加载,但预填充
价值消失了吗?这是呈现的HTML
<input class="string required" id="charity_first_name" name="charity[first_name]" size="50" type="text" />
是否有人可以建议如何预先填充Simple_Form并保留这些
服务器端验证失败并重新加载页面时的值?
谢谢。
推荐答案
如果您想让它与验证一起工作,您应该在控制器中预设对象值,如下所示:
@charity = Charity.new
@charity.first_name = params[:first]
这篇关于Rails Simple_Form服务器端验证丢失的URL参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文