我正在尝试创建订阅表单以便及早访问我的平台,但我无法想象。我使用的表单应该发送电子邮件到另一封电子邮件,其中包含订阅者的电子邮件。
我的问题是电子邮件是以表单提交方式发送的,但@new_email每次都是空的。
welcome_controller.rb:
class WelcomeController < ApplicationController
def home
end
def about
end
def subscribe
WelcomeMailer.subscribed(params[:Email][:email]).deliver
flash[:success] = "We've got your request, we'll be in touch"
redirect_to root_path
end
end
Subscribed.html.erb
<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
"You have a new subscriber!
Email : <% @new_email %>
Bye"
</body>
</html>
welcome_mailer.rb
class WelcomeMailer < ActionMailer::Base
default :from => "mail@mail.com"
def subscribed(params)
mail(:to => "myname@gmail.com", :subject => "We've got a new subscriber") do |format|
format.html {
render locals: { new_email: params }
}
end
end
end
我的表格:
<%= form_tag :subscribe, :url => {:controller => 'welcome', :action => 'subscribe'}, class:'navbar-form navbar-center',onsubmit: "return continueOrNot()" do %>
<div class="form-group">
<%= text_field 'Email','email', placeholder: "Enter email", class:'form-control',required: 'true'%>
<%= submit_tag 'Sign-in me in',:id=>'submit',class:'btn btn-info btn-xl' %>
<br/><small id="emailHelp" class="form-text text-muted">We'll never share your email with anyone else.</small>
</div>
<%end%>
感谢您的帮助
答案 0 :(得分:0)
好的,我已经找到了有罪的事情:
在subscribed.html.erb我需要 &lt;%= new_email%&gt;而不是&lt;%new_email%&gt; ......错字
@phoet你是对的。此外,我已从 text_field 切换到 text_field_tag 以获取更多名称/ ID控件。