【问题标题】:Specify HTML method in Formtastic action link在 Formtastic 操作链接中指定 HTML 方法
【发布时间】:2023-03-24 18:45:01
【问题描述】:

在 Formtastic semantic_form_for 中,我希望 Cancel 链接通过 delete 方法指向控制器的销毁操作:

= semantic_form_for @user, url: password_reset_path(params[:id]) do |f|
    = f.inputs do
        = f.input :password
        = f.input :password_confirmation
    = f.actions do
        = f.action :submit, label: 'Reset password'
        = f.action :cancel, label: 'Cancel password reset',
            as: :link, url: password_reset_path(params[:id]), html: { method: :delete }

这是我想要开始工作的html: { method: :delete } 部分,因此当用户单击取消 链接时,我的临时资源“密码重置”会立即通过password_resets#destroy 销毁.

请注意,这不是为整个表单指定 HTML 方法(正如其他地方所要求的那样)。

上面的代码忽略了DELETE方法,不知道怎么实现呢?

【问题讨论】:

    标签: ruby ruby-on-rails-3.1 formtastic


    【解决方案1】:

    使用button_html 选项。

    试试吧!

    <%= f.action :cancel, :label => "Cancelar", url: order_path(@order), button_html: {method: :delete} %>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-01-03
      • 1970-01-01
      • 2012-12-13
      • 1970-01-01
      • 2013-05-15
      • 1970-01-01
      • 2011-10-19
      • 1970-01-01
      相关资源
      最近更新 更多