简体   繁体   English

在没有模型的情况下验证电子邮件格式-Databasedotcom gem

[英]Validate email format without model - databasedotcom gem

I am new to Rails and I am using the salesforce gem, databasedotcom so there are is no model where I would normally validate the email address format, simple_form is validating presence but this error when an invalid email is entered: 我是Rails的新手,我使用的是salesforce gem,databasedotcom,因此没有可以正常验证电子邮件地址格式的模型,simple_form可以验证状态,但是输入无效电子邮件时会出现以下错误:

Databasedotcom::SalesForceError at /leads
Email: invalid email address:def create

Here is the controller: 这是控制器:

def create
 @lead = Lead.new(params[:lead])
 @lead['OwnerId'] = '005b0000000WxqE'   

 if @lead.save
   redirect_to @event
 else
   render "new"
 end
end

Here is the form: 形式如下:

<%= simple_form_for @lead, url: leads_path(@lead, event_id: params[:event_id]), method: :post do |f| %>
 <%= f.input :FirstName, :label => "First Name" %>
 <%= f.input :LastName, :label => "Last Name" %>
 <%= f.input :Email %>
 <%= f.input :Company %>
 <%= f.button :submit, value: "Submit" %>
<% end %>

I need to add something like 'if @lead.valid?' 我需要添加类似“ if @ lead.valid?”的内容 but im not sure what steps to take to make this work because that on its own doesn't work. 但是我不确定要采取什么措施才能使它正常工作,因为这本身是行不通的。

This seems to be an options for you, client_side_validations-simple_form gem has the simple_form with client_side_validation. 这似乎是您的一个选择, client_side_validations-simple_form gem具有带有client_side_validation的simple_form。

hope this helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM