红宝石,sinatra和haml中的联系表 [英] Contact form in ruby, sinatra, and haml

查看:91
本文介绍了红宝石,sinatra和haml中的联系表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是这三个人的新手,我正在尝试为网站编写一个简单的联系表.我想出的代码在下面,但是我知道它存在一些基本问题(由于我对sinatra的经验不足).对于使该工作正常进行的任何帮助,我们将不胜感激,我似乎无法找出/查找此类文档.

I'm new to all three, and I'm trying to write a simple contact form for a website. The code I have come up with is below, but I know there are some fundamental problems with it (due to my inexperience with sinatra). Any help at getting this working would be appreciated, I can't seem to figure out/find the documentation for this sort of thing.

haml代码:

%form{:name => "email", :id => "email", :action => "/contact", :method => "post", :enctype => "text/plain"}
  %fieldset
    %ol
      %li
        %label{:for => "message[name]"} Name:
        %input{:type => "text", :name => "message[name]", :class => "text"}
      %li
        %label{:for => "message[mail]"} Mail:
        %input{:type => "text", :name => "message[mail]", :class => "text"}
      %li
        %label{:for => "message[body]"} Message:
        %textarea{:name => "message[body]"}
    %input{:type => "submit", :value => "Send", :class => "button"}

这是我在sinatra的app.rb中的代码:

And here is my code in sinatra's app.rb:

require 'rubygems'
require 'sinatra'
require 'haml'
require 'pony'

    get '/' do
        haml :index
    end 

    get '/contact' do
        haml :contact
    end

    post '/contact' do
        name = #{params[:name]}
        mail = #{params[:mail]}
        body = #{params[:body]}     
        Pony.mail(:to => '*emailaddress*', :from => mail, :subject => 'art inquiry from' + name, :body => body) 
    end

推荐答案

我想为任何想知道的人弄清楚:

I figured it out for any of you wondering:

haml:

%form{ :action => "", :method => "post"}
  %fieldset
    %ol
      %li
        %label{:for => "name"} Name:
        %input{:type => "text", :name => "name", :class => "text"}
      %li
        %label{:for => "mail"} email:
        %input{:type => "text", :name => "mail", :class => "text"}
      %li
        %label{:for => "body"} Message:
        %textarea{:name => "body"}
    %input{:type => "submit", :value => "Send", :class => "button"}

和app.rb:

post '/contact' do
        name = params[:name]
        mail = params[:mail]
        body = params[:body]

        Pony.mail(:to => '*emailaddress*', :from => "#{mail}", :subject => "art inquiry from #{name}", :body => "#{body}")

        haml :contact
    end

这篇关于红宝石,sinatra和haml中的联系表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆