0

これは私のコントローラーです

class IdeasController < ApplicationController
  load_and_authorize_resource

  def create
    @idea = Idea.create params[:idea]
  end
end

私のアビリティファイルは

class Ability
  include CanCan::Ability

  def initialize(user)
    user ||= User.new
    if user.confirmed?  
      can :manage, Idea
    end
  end
end

しかし、私のspecは作成時に成功を返します

context "when not logged in"do
  it "does not be allowed" do
    post :create, FactoryGirl.attributes_for(:idea)
    response.should_not be_success
  end   
end

before_filter :authenticate_user!コントローラーに追加する必要がありますか?

4

1 に答える 1

0

試してください:cannot :create, Idea能力モデルで。

アップデート:

before_filter :authenticate_user!ユーザー認証を使用してコントローラーをセットアップするために必要です。

于 2013-09-17T05:42:08.863 に答える