Rails 5.1:发布请求无法正常工作

时间:2017-06-25 08:36:44

标签: ruby-on-rails post twilio ruby-on-rails-5 authy

在我的Rails 5.1应用中,我使用devise-authy gem将2fa添加到我的应用中。有了这个表格......

= enable_authy_form multipart: true do
    = text_field_tag :country_code, '', required: true, id: 'country_code', aria_required: 'true'
    = telephone_field :cellphone, '', required: true, autocomplete: 'off', id: 'authy-cellphone', class: 'string required', aria_required: 'true'
    = button 'button', I18n.t( 'enable_authy', { scope: 'devise' } ), nil, 'submit', true, 'flex-end'

...我发布到以下控制器操作(from the gem):

  def POST_enable_authy
    @authy_user = Authy::API.register_user(
      :email => resource.email,
      :cellphone => params[:cellphone],
      :country_code => params[:country_code]
    )

    if @authy_user.ok?
      resource.authy_id = @authy_user.id
      if resource.save
        set_flash_message(:notice, :enabled)
      else
        set_flash_message(:error, :not_enabled)
        redirect_to after_authy_enabled_path_for(resource) and return
      end

      redirect_to [resource_name, :verify_authy_installation]
    else
      set_flash_message(:error, :not_enabled)
      render :enable_authy
    end
  end

但是从日志中可以看出,没有任何反应:

Started POST "/2fa/enable" for 127.0.0.1 at 2017-06-24 21:19:02 +0200
Processing by Devise::DeviseAuthyController#POST_enable_authy as HTML
  Parameters: {"utf8"=>"✓", "authenticity_token"=>"5P1aSzQvWATGEBLEYYwoD7dS/6sCSzpAk24rnh1DK9ZV6S70WWt10ijmoAo9MlxyGDAol+ewZYAszooiDeZKQQ==", "country"=>"United States", "country_code"=>"us", "cellphone"=>["546876578"], "subdomain"=>""}
Cookie#domain returns dot-less domain name now. Use Cookie#dot_domain if you need "." at the beginning.
  Rendering devise/devise_authy/enable_authy.html.haml within layouts/application
Completed 200 OK in 3632ms (Views: 2461.8ms | ActiveRecord: 1.5ms)

它只是重定向到请求源自的模板。我不明白为什么会这样。

即使在分配了gem之后,修改控制器以重定向到特定的URL,也没有任何反应。

1 个答案:

答案 0 :(得分:1)

我不确定它是否适用,因为我使用Ruby / Sinatra体验过它​​。我的帖子似乎是正确的,但它一直保持原来的形式。问题出在AJAX上,这是默认的。由于AJAX打算更新表单,否则不会重定向。我指定data-ajax =“false”来解决它。如果有帮助,请告诉我。 (发表评论作为答案。)

相关问题