11

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

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

尝试通过表单发送数据时收到此网址:10.0.0.2:3000/activation。我知道我可以制定tool#activation激活路线,但这是一种错误的方式,我想将帖子查询发送到10.0.0.2:3000/tool/activation,但:action => 'tool/activation'据我了解也是一种不好的方式。

你能给我建议吗?

4

1 回答 1

20

您应该使用 rails 辅助标签。

= 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。

于 2012-06-14T16:09:15.630 回答