我一直在从事我的应用程序的工作,在该应用程序中我有许多角色,也有一些用户。

但是突然之间我无法注册了。 登录可以正常工作,但是注册始终会将我重定向到签名页面,并产生相同的错误:

在此处输入图片说明

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

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

===============>>#1 票数:0

您正在执行before_filter :authenticate_user! 在您的RegistersController中(最有可能)。 这就是产生401响应和带有Devise的即显消息的原因。 CanCan应该与它无关。 发布您的RegistersController。

===============>>#2 票数:0

确定找出了问题所在。

由于我有一个名为Registration.html.erb的文件和一个操作名称registration我的路由如下所示:

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

问题是Devise在内部使用此动作名称,因此我的代码被错误地路由。

为了解决这个问题,我将名为registration所有内容都更改为take_register ,如下所示:

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

那对我来说成功了,现在一切正常

  ask by omarArroum translate from so

未解决问题?本站智能推荐: