【问题标题】:Rails / Haml: How to create a post form?Rails / Haml:如何创建帖子表单?
【发布时间】:2012-06-17 17:07:53
【问题描述】:

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

%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' 也是一个不好的方式。

你能给我建议吗?

【问题讨论】:

    标签: ruby-on-rails forms haml


    【解决方案1】:

    你应该使用 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。

    【讨论】:

    • 不客气!请务必接受答案,这样有类似问题的任何其他人都会知道什么对您有用。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-12-15
    • 1970-01-01
    • 1970-01-01
    • 2013-10-13
    • 2023-03-12
    • 1970-01-01
    相关资源
    最近更新 更多