Ruby-on-rails Rails / Haml:如何创建帖子表单?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11036954/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Rails / Haml: How to create a post form?
提问by alterpub
I'm trying to make a simple form, but it's working not so fine. This is my current form code:
我正在尝试制作一个简单的表格,但效果不佳。这是我当前的表单代码:
%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" }
I am getting this url when trying to send data via form: 10.0.0.2:3000/activation.
I know that I can make route tool#activationto activation, but it's a wrong way, I want to sent post query to 10.0.0.2:3000/tool/activation, but :action => 'tool/activation'also is a bad way as far as I understand.
尝试通过 form: 发送数据时,我得到了这个 url 10.0.0.2:3000/activation。我知道我可以制作tool#activation激活路线,但这是一种错误的方式,我想将帖子查询发送到10.0.0.2:3000/tool/activation,但:action => 'tool/activation'据我所知也是一种糟糕的方式。
Can you give me advice ?
你能给我建议吗?
回答by MrDanA
You should use the rails helper tags.
您应该使用 rails helper 标签。
= form_tag tool_activation_path, :method => :post do
# The table
# The row
# The data
= text_field_tag "accountName", ""
= submit_tag "Submit"
See more here: http://api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html
在此处查看更多信息:http: //api.rubyonrails.org/classes/ActionView/Helpers/FormTagHelper.html
Also, you should try to avoid unnecessary tables to style your layout. Instead, look to using CSS.
此外,您应该尽量避免使用不必要的表格来设置布局样式。相反,请考虑使用 CSS。

