模型/ lead.rb
class Lead < MailForm::Base
attribute :fullname
def headers
{
:subject => "My Contact Form",
:to => "callumshorty@hotmail.com",
:from => "admin@uk-franchise.co.uk"
}
end
end
控制器/ lead_form_controller.rb
class LeadFormController < ApplicationController
def new
@lead = Lead.new
end
def create
@lead = Lead.new(params[:lead_form])
@lead.request = request
@lead.deliver
end
end
的routes.rb
resources :lead_form
视图/列表/ show.html.erb
<%= form_for @lead, :url => url_for(:controller => 'lead_form', :action => 'new') do |lead| %>
<%= lead.text_field :fullname %>
<%= lead.submit %>
<% end %>
尝试访问节目页时出错:
First argument in form cannot contain nil or be empty
在线:
<%= form_for @lead, :url => url_for(:controller => 'lead_form', :action => 'new') do |lead| %>
任何帮助都会受到超级赞赏,无法忍受这些邮件:(
答案 0 :(得分:0)
您的@lead需要在ListingsController#show action中初始化,因为您的潜在客户表单位于该视图中。尝试在ListingsController#show method中添加@lead = Lead.new
。