gpt4 book ai didi

ruby-on-rails - Rails/Haml : How to create a post form?

转载 作者:行者123 更新时间:2023-12-04 03:08:48 25 4
gpt4 key购买 nike

我正在尝试制作一个简单的表格,但效果不佳。
这是我当前的表单代码:

%form{ :controller => 'tool', :action => 'activation', :method => 'post' }
%table{ :border => 0, :width => "100%", :height => "100%" }
%tr{ :align => "center", :valign => "center" }
%td
%input{ :type => "text", :name => "accountName" }
%input{ :type => "submit", :name => "submit", :value => "login" }

尝试通过表单发送数据时,我收到此 url: 10.0.0.2:3000/activation .
我知道我可以做路由 tool#activation激活,但方法错误,我想发送post查询到 10.0.0.2:3000/tool/activation ,但是 :action => 'tool/activation'据我所知,这也是一种糟糕的方式。

你能给我建议吗?

最佳答案

您应该使用 rails helper 标签。

= form_tag tool_activation_path, :method => :post do
# The table
# The row
# The data
= text_field_tag "accountName", ""
= submit_tag "Submit"

在此处查看更多信息: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html

此外,您应该尽量避免使用不必要的表格来设置布局样式。相反,请考虑使用 CSS。

关于ruby-on-rails - Rails/Haml : How to create a post form?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11036954/

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