Haml 表单未在 Sinatra 应用程序中提交

发布于 2024-12-11 00:46:11 字数 697 浏览 0 评论 0原文

由于我已经在一个简单的 sinatra 应用程序中从 erb 转换为 haml,因此我在提交表单时遇到了问题。

new.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 一起工作得很好?

I'm having problems submitting my form now that I've converted from erb to haml in a simple sinatra app.

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

In my 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

each time I get the Hello World statement appear. My logs show nothing interesting.

Any ideas? Worked just fine with erb??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

哆啦不做梦 2024-12-18 00:46:11

这是我测试过的

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

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

并且它按预期工作。因此,由于某种原因 radcheck.save 返回 false,但这与 haml 无关。 (但请注意,我已使用 :name => "username" 更正了输入)

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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文