Ruby on rails Rails验证jquery上的字段隐藏/显示
我有一个复选框来显示送货地址如果一个项目有Ruby on rails Rails验证jquery上的字段隐藏/显示,ruby-on-rails,ruby,ruby-on-rails-3,Ruby On Rails,Ruby,Ruby On Rails 3,我有一个复选框来显示送货地址如果一个项目有菜单类型='sunch',表单的这部分将使用jQuery隐藏,直到选中复选框为止,但是如果选中复选框,我如何验证这些字段 看法 听起来你在找。看起来像 validates :delivery_line_1, presence: true, if: :lunch_delivery class Order < ActiveRecord::Base attr_accessible :billing_line_1, :billing_line_2,
菜单类型='sunch'
,表单的这部分将使用jQuery隐藏,直到选中复选框为止,但是如果选中复选框,我如何验证这些字段
看法
听起来你在找。看起来像
validates :delivery_line_1, presence: true, if: :lunch_delivery
class Order < ActiveRecord::Base
attr_accessible :billing_line_1, :billing_line_2, :billing_line_3, :billing_postcode, :delivery_line_1, :delivery_line_2, :delivery_line_3, :delivery_postcode, :phone_number, :email, :first_name, :last_name, :lunch_delivery
validates :first_name, presence: true
validates :last_name, presence: true
validates :email, presence: true
validates :billing_line_1, presence: true
validates :billing_postcode, presence: true
validates :phone_number, presence: true
end
$("#order_lunch_delivery").click ->
if $(this).is(":checked")
$("#deliveryAddress").show()
else
$("#deliveryAddress").hide()
return
validates :delivery_line_1, presence: true, if: :lunch_delivery