gpt4 book ai didi

ruby - ruby、sinatra 和 haml 中的联系表单

转载 作者:数据小太阳 更新时间:2023-10-29 06:26:52 24 4
gpt4 key购买 nike

我是这三个方面的新手,我正在尝试为网站编写一个简单的联系表。我想出的代码如下,但我知道它存在一些基本问题(由于我对 sinatra 缺乏经验)。任何帮助完成这项工作的帮助将不胜感激,我似乎无法弄清楚/找到此类事情的文档。

来自联系页面的 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 中的代码:

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

最佳答案

我为你们中的任何一个想出了这个问题:

哈姆:

%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

关于ruby - ruby、sinatra 和 haml 中的联系表单,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2068148/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com