1

I'm creating a contact page with the usual form, and I found Pony which seemed to fit the bill for what I needed. The site is basically static, so is built using Middleman, but I've been reading around and figured to add a contact form Sinatra would be helpful.

I have my form; I have my ruby code, but I'm having difficulty pulling them together. I seem to be missing something that will trigger the ruby code.

The form, in /source/contact-us.html.haml :

    %form.contact{ :action => "/contact-us.html", :method => "post"}
      %fieldset

        %label{:for => "name"} Full name *
        %input{:type => "text", :name => "name"}

        %label{:for => "email"} Email addresss *
        %input{:type => "text", :name => "email"}

        %label{:for => "phone"} Phone *
        %input{:type => "text", :name => "phone"}

        %input{:type => "submit", :value => "Send", :class => "read-more"}

And the ruby code (currently in /mail.rb) :

require 'sinatra'
require 'pony'

post '/contact-us.html' do
  options = {
    :to => '[my email]',
    :from => params[:email],
    :subject => params[:name],
    :body => params[:phone]
  }

  Pony.mail(options)

  redirect '/thankyou.html'
end

I'm testing things out both locally and hosted on a server that I've verified is running Ruby (which is always a good start ;) )

I've had a look elsewhere on stackoverflow and I found things like these, but nothing that helped me solve my problem :

Contact form in ruby, sinatra, and haml

Sending mail with Pony and Sinatra

This is the first time I'm using Ruby and Middleman for a site, so I'm learning lots - I can't help but feel that I've missed something fairly obvious here..

Community
  • 1
  • 1
aurumpotestasest
  • 766
  • 7
  • 18

0 Answers0