我应该将参数从表单发送到控制器,然后将它们发送到模型。我需要在模型中检查它们。请帮助... 表格:
<form action="questions">
<input type="text" name="user_name_param" /><br>
<input type="text" name="user_email_param" /><br>
<input type="submit" name="send" />
</form>
问题控制器:
user_id = User.new.check_user(params[:user_name_param], params[:user_email_param])
用户模型:
validates :name_param, :presence => true,
:length => {:minimum => 1, :maximum => 254}
validates :email_param, :presence => true,
:length => {:minimum => 3, :maximum => 254},
:uniqueness => true,
:format => {:with => /^([^@\s]+)@((?:[-a-z0-9]+\.)+[a-z]{2,})$/i}
def check_user(name_param, email_param)
if (name_param && email_param).valid?
User.where(:user_name => name_param, :user_email => email_param).first.try(:id) || false
else render :template => "questions/auth_form"
end
结尾
我有未定义的方法“有效吗?” 对于 nil:NilClass错误。