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
How to Generate a Random Date in Ruby
Setting Ruby Hash .Default to a List
Rails Development Server Is Slow and Takes a Long Time to Load a Simple Page
Error When Starting Rails Server: Warning: Insecure World Writable Dir /Usr in Path, Mode 040777
How to Rescue Model Transaction and Show the User an Error
How to Filter an Array of Hashes to Get Only the Keys in Another Array
Why Should I Use Rspec or Shoulda with Rails
Testing Actionmailer Multipart Emails(Text and HTML Version) with Rspec
Ubuntu 12 - How to Install Ruby and Rails Correctly
Ruby Net::Http::Get and JSON Responses
Ruby on Rails, Could Not Find a Valid Gem 'Rails'
Which Ruby Gems Support the Facebook API
Namespaced Models in Rails: What's the State of the Union
Rails Console Running Incredibly Slowly When Editing Text
How to Create a Rest API for a Ruby Application