ActionView :: Template :: Error(未定义的方法`protect_against_forgery?'用于#&lt;#<class:0x85f1220>:0x85fa808&gt;):

时间:2016-08-13 10:37:08

标签: ruby-on-rails ruby devise

我在api服务中使用devise gem得到了错误

我搜索过但没有帮助

undefined method `protect_against_forgery?' for #<#<Class:0x0

我做了

class UsersSessionsController < Devise::SessionsController

  before_action :resource
  before_action :resource_name
  before_action :devise_mapping
  before_action :protect_against_forgery?

  def new
    super
  end

  def create
    super
  end

  def resource_name
    :user
  end

  def resource
    @resource ||= User.new
  end

  def devise_mapping
    @devise_mapping ||= Devise.mappings[:user]
  end

  def protect_against_forgery?
    true
  end
end

然后路线

  devise_for :users, :controllers => {:sessions => "users_sessions"}
  resources :users_sessions

还会在本地生成视图。

请帮忙

我也看到了

https://github.com/plataformatec/devise/issues/4003

我的观点

登录

<%= form_for(:user, url: new_users_session_path) do |f| %>
  <div class="field">
    <%= f.label :email %><br />
    <%= f.email_field :email, autofocus: true %>
  </div>

  <div class="field">
    <%= f.label :password %><br />
    <%= f.password_field :password, autocomplete: "off" %>
  </div>

  <%# if devise_mapping.rememberable? -%>
    <div class="field">
      <%= f.check_box :remember_me %>
      <%= f.label :remember_me %>
    </div>
  <%# end -%>

  <div class="actions">
    <%= f.submit "Log in" %>
  </div>
<% end %>

0 个答案:

没有答案