Contact Form in Ruby, Sinatra, and Haml

Contact form in ruby, sinatra, and haml

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"}

And the 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

Haml Form Not Submitting in Sinatra App

This is what I've tested

get '/new' do
haml :new
end

post '/new' do
#radcheck = Radcheck.new(:username => params[:username])
username = params[:username]
if username
username
else
"Hello World"
end
end

and new.haml

%form{ :action => "/new", :method => "post"}
%fieldset
%ol
%li
%label{:for => "username"} Name:
%input{:type => "text", :name => "username", :class => "text"}
%input{:type => "submit", :value => "Send", :class => "button"}

And it works as expected. So for some reason radcheck.save is returning false, but that has nothing to do with haml. (But notice that I have corrected input with :name => "username")

Using Ruby and Sinatra, Is it possible to use HAML in an internal or inline manner?

You should be able to use Haml::Engine#render to convert the Haml to HTML like so:

get '/abc2' do
Haml::Engine.new(<<-Haml).render(binding)
%b aaaaaa
Haml
end

This uses a heredoc (everything between the <<-Haml line and the closing Haml. binding is a special variable that basically refers to the current scope.

HAML Pass partial dynamically to layout in Sinatra app

Ah it was so simple afterall.. With the help of this question, I realized now of course that everything is wrapped with layout.haml and I simply needed to place the appopriate yield statement.

layout.haml

!!!
%html
%head
= partial :head
%body
= partial :header
= yield
= partial :footer

And call the template as usual:

get '/test' do    
haml :"test/index"
end

Sinatra haml Select and Delete several files

You should use var = params["checkbox"], since the params key is not a symbol, but a string.

Using ChartKickjs with Sinatra and HAML

According to haml docs this:

%barchart[@estimates]

Will try to create a <barchart> html tag and use @estimates to set its id and class.

http://haml.info/docs/yardoc/file.REFERENCE.html#object_reference_

What I think you are trying to achieve is this:

= bar_chart @estimates


Related Topics



Leave a reply



Submit