Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
403 views
in Technique[技术] by (71.8m points)

ruby on rails - I don't get why this platformatic mail form contact form isn't working

models/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

controllers/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

views/listings/show.html.erb

<%= form_for @lead, :url => url_for(:controller => 'lead_form', :action => 'new') do |lead| %>
  <%= lead.text_field :fullname %>
  <%= lead.submit %>
<% end %>

The error when trying to access the show page:

First argument in form cannot contain nil or be empty

On line:

<%= form_for @lead, :url => url_for(:controller => 'lead_form', :action => 'new') do |lead| %>

Any help would be super appreciated, can't stand these mailers :(

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Your @lead needs to be initialised in the ListingsController#show action, since your lead form is in that view. Try adding @lead = Lead.new in the ListingsController#show method.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...