Rails ajax发布简单形式:为什么要求GET?

时间:2017-02-22 10:44:07

标签: ruby-on-rails

我正在尝试使用简单的表单创建一个ajax更新操作,我不知道为什么浏览器会发出“获取”请求而不是“补丁”。

在我看来,我有

= simple_form_for current_user, url: certificate_webex_employee_path(current_user), remote: true, html: { class: 'edit-profile' }, defaults: { label: false } do |f|
          .form-body
            .form-group.row
              .col-md-12{style: 'color: black'}
                = f.input_field :webex_certification_code, class: "form-control"

我的routes.rb

resources :users, controller: 'employees', path: 'employees', as: 'employees', only: [:index, :edit, :update, :show, :destroy] do
    get :performance, on: :collection
    member do
      patch :certificate_webex
    end
  end

当然在控制器中我有certificate_webex方法。

为什么我提交动作时是“请求方法:GET”??? 我的表单不会调用certificate_webex方法。

修改

我也尝试用

=form_for current_user, url: certificate_webex_employee_path(current_user), method: :patch, remote: true, html: { class: 'edit-profile' }, defaults: { label: false } do |f|
 = f.text_field :webex_certification_code, class: "form-control"

1 个答案:

答案 0 :(得分:0)

尝试在form_for

中指定方法
:method => :patch

我没有使用过simple_form_for gem,但默认的rails form_for docs在这里引用:http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html