【发布时间】:2011-06-11 23:24:39
【问题描述】:
我有一个似乎是非标准的注册流程:
[欢迎!输入您的电子邮件和密码] => [酷,输入更多信息] => [注册]
我无法让 rails 识别出我只想验证第 1 页上的电子邮件和密码,以及第 2 页上的所有其他内容。
当用户点击网站时,他们会看到我的欢迎页面:
class WelcomeController < ApplicationController
def index
@user = User.new
end
end
<%= form_for(@user) do %>
<div class="formItem">
<%= label_tag(:email, "Your email address:") %>
<%= text_field(:user, :email) %>
<br clear="all" />
</div>
<div class="formItem">
<%= label_tag(:password, "Select a password:") %>
<%= password_field_tag(:password) %>
<br clear="all" />
</div>
<%= submit_tag("Sign up today - it's free and easy!", :class => "submitForm") %>
<% end %>
=
class UsersController < ApplicationController
def create
@user = User.new(params[:user])
if @user.save
redirect_to(edit_user_path(@user, :noticeHeader => true ), :notice => 'Please take a minute and answer these additional questions.')
else
render :action => "welcome/index"
end
end
=
一旦他们点击注册,他们就会看到我的下一页表单域。
我遇到的问题是我在用户模型中验证了两个页面上的字段。由于这些字段不在欢迎页面上,因此我在提交欢迎页面时收到“未定义的局部变量或方法”错误。例如,我 validates_presence_of :title 因为我希望 title 是必需的,但它只列在第 2 页上,因此第 1 页无法正确验证。
关于如何处理的想法?
谢谢。
【问题讨论】: