0

我一直在开发我的应用程序,其中我有许多角色和一些用户。

但是突然间我不能再注册了。登录工作正常,但注册总是将我重定向回签名页面并产生相同的错误:

在此处输入图像描述

当我尝试注册时,控制台总是显示以下内容:

Started POST "/registers/user/registration" for 127.0.0.1 at 2013-04-18 00:48:22 +0100
Processing by RegistersController#registration as HTML
  Parameters: {"utf8"=>"✓",     "authenticity_token"=>"ofucDxxzZFbTVLfVaA3QxixOHL2V9hzxfSFU/99Pd60=", "user"=>{"name"=>"Omar Arroum", "email"=>"omar@gmail.com", "password"=>"[FILTERED]", "password_confirmation"=>"[FILTERED]"}, "commit"=>"Sign up", "id"=>"user"}
Completed 401 Unauthorized in 1ms

Started GET "/users/sign_in" for 127.0.0.1 at 2013-04-18 00:48:22 +0100
Processing by Devise::SessionsController#new as HTML
  Rendered devise/shared/_links.html.erb (0.4ms)
  Rendered devise/sessions/new.html.erb within layouts/application (9.8ms)
  Rendered layouts/_navigation.html.erb (1.3ms)
  Rendered layouts/_messages.html.erb (0.1ms)
Completed 200 OK in 63ms (Views: 61.6ms | ActiveRecord: 0.0ms)

我没有对 `user_controller.rb 进行任何更改,所以不确定是什么导致了这个问题

编辑:添加了RegistersController

class RegistersController < ApplicationController
  #before_filter :authenticate_user!
  load_and_authorize_resource

  # GET /registers
  # GET /registers.json
  def index
    @registers = Register.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @registers }
    end
  end

  # GET /registers/1
  # GET /registers/1.json
  def show
    @register = Register.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.json { render json: @register }
    end
  end

  # GET /registers/new
  # GET /registers/new.json
  def new
    @register = Register.new(:event_id => params[:event_id])
    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @register }
    end
  end

  # GET /registers/1/edit
  def edit
    @register = Register.find(params[:id])
  end

  # POST /registers
  # POST /registers.json
  def create
    @register = Register.new(params[:register])

    respond_to do |format|
      if @register.save
        format.html { redirect_to @register, notice: 'Register was successfully created.' }
        format.json { render json: @register, status: :created, location: @register }
      else
        format.html { render action: "new" }
        format.json { render json: @register.errors, status: :unprocessable_entity }
      end
    end
  end

  # PUT /registers/1
  # PUT /registers/1.json
  def update
    @register = Register.find(params[:id])

    StudentRegister.find_all_by_register_id(@register).each do |streg|
      streg.update_attributes(:present => false, :late => false)
      #sets the users status as being absent, mainly for the purpose of when copying a new register,
      #as the presence and lateness is otherwise maintained
    end

    respond_to do |format|
      if @register.update_attributes(params[:register])
        format.html { redirect_to @register, notice: 'Register was successfully updated.' }
        format.json { head :no_content }
      else
        format.html { render action: "edit" }
        format.json { render json: @register.errors, status: :unprocessable_entity }
      end
    end
  end

  # DELETE /registers/1
  # DELETE /registers/1.json
  def destroy
    @register = Register.find(params[:id])
    @register.students.delete_all_on_destroy
    @register.destroy

    respond_to do |format|
      format.html { redirect_to registers_url }
      format.json { head :no_content }
    end
  end

  def registration
    @studentregister = StudentRegister.find_all_by_register_id(params[:id])

  end

  def copy
    @register = Register.find(params[:id]).amoeba_dup #Creates a duplicate of the existing register with all Students in it
    @register.date = Date.today #Sets the registers date to today's date
    @register.save

    respond_to do |format|
      format.html { redirect_to edit_register_path(@register) } #Redirects to the edit page so that they can make any updates
      format.json { head :no_content }
    end
  end
end
4

2 回答 2

0

好的,找出问题所在。

由于我有一个名为的文件Registration.html.erb和一个动作名称,registration我的路线看起来像这样:

match 'registers/:id/registration' => 'registers#registration', :as => 'registration'  #Route for taking the register

问题是 Devise 在内部使用了这个动作名称,所以我的代码被错误地路由了。

为了解决这个问题,我将所有名称更改为registrationtake_register如下所示:

match 'registers/:id/take_register' => 'registers#take_register', :as => 'take_register'  #Route for taking the register

这对我有用,现在一切正常

于 2013-04-18T02:13:07.087 回答
0

您正在before_filter :authenticate_user!您的 RegistersController 中进行操作(很可能)。这就是使用 Devise 产生 401 响应和闪现消息的原因。CanCan应该与它无关。发布您的 RegistersController。

于 2013-04-18T00:59:18.070 回答