【发布时间】:2011-10-18 16:49:58
【问题描述】:
现在我在一个简单的 sinatra 应用中从 erb 转换为 haml,提交表单时遇到问题。
新的.haml
%form{ :action => "/new", :method => "post"}
%fieldset
%ol
%li
%label{:for => "username"} Name:
%input{:type => "text", :username => "name", :class => "text"}
%input{:type => "submit", :value => "Send", :class => "button"}
在我的 app.rb 中
get '/new' do
haml :new
end
post '/new' do
radcheck = Radcheck.new(:username => params[:username])
if radcheck.save
redirect '/'
else
"Hello World"
end
end
每次我得到 Hello World 语句时都会出现。我的日志没有显示任何有趣的内容。
有什么想法吗?与 erb 一起工作得很好??
【问题讨论】:
-
你粘贴正确了吗?
:username => "name"不应该反过来吗? -
@Slartibartfast - 我也试过 %input{:type => "textbox", :username => "username", :id => "username"} 没有成功:(
-
你试过
:name => "username"吗? -
@Slartibartfast 也不起作用,仍然无法保存。我需要调整我的行为吗?
-
请注意,使用 Haml 时,您可以使用 HTML-style attributes 为简单起见,例如
%form(action="new" method="post")或%label(for="username);只有当您需要对值使用复杂的 Ruby 表达式时,使用 Ruby 哈希的好处才会出现;否则,它只是更多的打字。