"您已登录。"不会禁用

时间:2014-12-28 19:52:02

标签: ruby-on-rails devise

尝试实施管理控制面板以创建用户。我有2个设计模型,管理员和分支机构。我还有一个管理员控制器,它保存创建视图:

<%= form_for(resource, :as => resource_name, :url => session_path(resource_name)) do |f| %>

  <div><%= f.label :branch %><br />
  <%= f.text_field :branch, autofocus: true %></div>

  <div><%= f.label :email %><br />
  <%= f.email_field :email %></div>

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

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

  <div><%= f.submit "Sign up" %></div>

<% end %>

然后我创建了自己的设计注册控制器来覆盖/编辑params和create方法:

class RegistrationsController < Devise::RegistrationsController
    prepend_before_filter :require_no_authentication, only: [ :cancel ]
  private

  def sign_up_params
    params.require(:branch).permit(:branch, :email, :password, :password_confirmation)
  end

  def account_update_params
    params.require(:branch).permit(:branch, :email, :password, :password_confirmation, :current_password)
  end

  def create
    build_resource(sign_up_params)

    resource_saved = resource.save
    yield resource if block_given?
    if resource_saved
      if resource.active_for_authentication?
        set_flash_message :notice, :signed_up if is_flashing_format?
        sign_up(resource_name, resource)
        respond_with resource, location: after_sign_up_path_for(resource)
      else
        set_flash_message :notice, :"signed_up_but_#{resource.inactive_message}" if is_flashing_format?
        expire_data_after_sign_in!
        respond_with resource, location: after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      set_minimum_password_length
      respond_with resource
    end
  end

end

我使用以下路线:

  devise_for :branches, :controllers => { registrations: 'registrations' }
  devise_for :admins

然而问题仍然存在,当我以管理员身份登录并且我正在访问由管理员控制器控制的新网站视图时,我填写表单,点击提交并且无法创建带有通知的条目作者:您已经登录。

有什么想法吗?

0 个答案:

没有答案