【发布时间】:2012-06-14 11:13:53
【问题描述】:
我尝试验证是否存在属于另一个模型的属性,但无济于事。
拥有
- 用户模型
- 个人资料模型
使用这种形式:
= simple_form_for(resource, :as => resource_name, :html => { :class => 'form-horizontal' } , :validate => true , :url => registration_path(resource_name)) do |f|
= f.input :username, :label => t(:username)
= f.input :email, :label => t(:email),
:hint => t(:hint_email_visible)
= f.input :password, :label => t(:password), :require => true
= f.input :password_confirmation, :label => t(:password_confirm)
- resource.build_profile
= f.fields_for :profile do |f|
#render
= f.hidden_field :form, :value => "signup"
.clear
= f.input :gender,
:label => t(:your_gender),
:collection => gender,
:item_wrapper_class => 'inline',
:as => :radio_buttons
.clear
= f.button :submit, t(:submit, :scope => :register) + " »"
如何使用上述表单设置验证性别字段的存在?
【问题讨论】:
-
嗨,为什么不在代码中使用accepts_nested_attributes_for?
-
能否详细说明这一点,并提供一个简短的例子来说明这应该如何提供帮助?
-
谢谢,这正是我所需要的,谢谢,如果您将其发布为回复而不是评论,我可以为您提供正确的答案。
标签: ruby-on-rails-3 validation activerecord model