RoR 4.1中不推荐使用的警告

时间:2014-03-18 06:08:31

标签: ruby-on-rails ruby devise

我正在编写我的Devise / CanCan组合授权设置并运行一些调试。

每次刷新浏览器时,我都会遇到这种说法。

Admin::UsersController#index处理为HTML

DEPRECATION WARNING: Relation#first with finder options is deprecated. Please bu
ild a scope and then call #first on it instead. (called from C:in `first':)

弃用警告说它来自C:in'first'。

但那应该是什么意思?!?

在我的RoR环境中,我应该在哪里找到它?看起来它可以在C文件夹中找到。但我的ROR项目是在D驱动器上,而不是C!

之前有人看过这个警告吗?

class Admin::UsersController < Admin::AdminController

load_and_authorize_resource



#def get_user
#  @current_user = current_user
#end

# GET /users
# GET /users.json
def index

  @users = User.all

  #@users = User.accessible_by(current_ability, :index).limit(20)

  respond_to do |format|
    format.json { render :json => @users }
    format.xml  { render :xml => @users }
    format.html
  end

end

# GET /users/1
# GET /users/1.json
def show

 @user = User.find(params[:id])

 respond_to do |format|
   format.json { render :json => @user }
   format.xml  { render :xml => @user }
   format.html      
 end
end

# GET /users/new
def new
  @user = User.new

  respond_to do |format|
    format.json { render :json => @user }   
    format.xml  { render :xml => @user }
    format.html
  end

  rescue ActiveRecord::RecordNotFound
    respond_to_not_found(:json, :xml, :html)
end



# GET /users/1/edit
def edit
  @user = User.find(params[:id])

  respond_to do |format|
    format.json { render :json => @user }   
    format.xml  { render :xml => @user }
    format.html
  end

  rescue ActiveRecord::RecordNotFound
    respond_to_not_found(:json, :xml, :html)

end

# POST /users
# POST /users.json
def create
  @user.attributes = params[:user]
  @user.role_ids = params[:user][:role_ids] if params[:user]
  @user = User.new(params[:user])

  respond_to do |format|
    if @user.save
      flash[:notice] = flash[:notice].to_a.concat @user.errors.full_messages
      format.html { redirect_to root_url, notice: 'Signed Up!' }
      format.json { render action: 'show', status: :created, location: @user }
    else
      flash[:notice] = flash[:notice].to_a.concat @user.errors.full_messages
      format.html { render action: 'new' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end
end

# PATCH/PUT /users/1
# PATCH/PUT /users/1.json
def update
  @user = User.find(params[:id])
  if params[:user][:password].blank?
    [:password,:password_confirmation,:current_password].collect{|p|    params[:user].delete(p) }
  else
    @user.errors[:base] << "The password you entered is incorrect" unless @user.valid_password?(params[:user][:current_password])
  end

  respond_to do |format|
    if @user.update(user_params)
      format.html { redirect_to @user, notice: 'User was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: 'edit' }
      format.json { render json: @user.errors, status: :unprocessable_entity }
    end
  end

  rescue ActiveRecord::RecordNotFound
   respond_to_not_found(:js, :xml, :html)
end

# DELETE /users/1
# DELETE /users/1.json
def destroy
  user = User.find(params[:id])

  @user.destroy
  respond_to do |format|
    format.html { redirect_to users_url }
    format.json { head :no_content }
  end

  rescue ActiveRecord::RecordNotFound
   respond_to_not_found(:json, :xml, :html)
end

private
# Use callbacks to share common setup or constraints between actions.
def set_user
    #@user = User.find(params[:id])
end

# Never trust parameters from the scary internet, only allow the white list through.
def user_params
  params.require(:user).permit(:username, :password, :password_confirmation)
end
end

0 个答案:

没有答案