电子邮件验证Flash消息无法正常工作

时间:2013-12-26 22:32:00

标签: ruby-on-rails ruby twitter-bootstrap

我的错误检查消息似乎有问题。我所拥有的只是一个控制器中的3个字段,用于联系我们表单,通过电子邮件发送站点所有者(通过gmail smtp)。一个是该人的电子邮件,主题和消息。我真正检查的是,如果字段是空白的,并且用户是否在有效的电子邮件中输入。验证检查似乎工作正常,并不分别发送电子邮件。但是,我的错误消息消息不会提示消息究竟出了什么问题。这是我的控制器的样子:

class AboutController < ApplicationController
# ...\controllers\home_controller.rb
#----------------------------------------------------
# show contact form

def contact
@title = "Contact"
@sender = ''
@subject = ''
@message = ''
end

def sendmail
@sender = params[:sender]
@subject = params[:subject]
@message = params[:message]
if validate(@sender, @subject, @message)
  UserEmail.contact(@sender, @subject, @message).deliver      
  flash[:success] = "Your message sent sucessfully!"      **//This message works**
  redirect_to about_index_path
else

flash.now[:error] = "Your message did not send, please make sure all fields are 

appropriately filled out." **//This message does not.** 

  redirect_to about_index_path
end
end

private
def validate(sender, subject, message)
  @email_regex = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i
  if sender.blank? || subject.blank? || message.blank?

    return false
elsif sender[@email_regex].nil?

    return false
  else
    return true
  end
end
end

Application_html.erb

<% flash.each do |type, message| %>

<div class="alert <%= flash_class type %>">
    <button class="close" data-dismiss="alert">x</button>
    <%= message %>

    </div>

1 个答案:

答案 0 :(得分:1)

您正在使用flash.now来处理那个无法正常工作的人。{/ p>