2013-10-19 28 views
0

權威人士寶石一直試圖implament在軌權威人士的寶石,它沒有顯示在我的索引頁,不知道爲什麼,我的錯誤消息指出問題,實現在軌

1) Error: 
DeletingAPost Feature Test#test_0001_delete the post: 
Capybara::ElementNotFound: Unable to find link or button "Destroy" 
    /Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/finders.rb:41:in `block in find' 
    /Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/base.rb:81:in `synchronize' 
    /Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/finders.rb:30:in `find' 
    /Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/node/actions.rb:13:in `click_link_or_button' 
    /Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/session.rb:354:in `block (2 levels) in <class:Session>' 
    /Users/cheatermoves/.rvm/gems/ruby-2.0.0-p247/gems/capybara-2.1.0/lib/capybara/dsl.rb:51:in `block (2 levels) in <module:DSL>' 
    /Users/cheatermoves/newHW/Portfolio/test/features/post_delete_post_test.rb:7:in `block (2 levels) in <top (required)>' 

這裏是我的索引的副本

<h1>Listing posts</h1> 

<table> 
    <tr> 
    <th>Title</th> 
    <th>Content</th> 
    <th></th> 
    <th></th> 
    <th></th> 
    </tr> 

<% @posts.each do |post| %> 
    <tr id="<%= dom_id(post) %>"> 
    <td><%= post.title %></td> 
    <td><%= post.content %></td> 
    <td><%= link_to 'Show', post %></td> 
    <% if policy(post).update? %> 
    <td><%= link_to 'Edit', edit_post_path(post) %></td> 
    <% end %> 
    <% if policy(post).destroy? %> 
     <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td> 
     <% end %> 
    </tr> 
    <% end %> 
</table> 

<%= link_to 'New Post', new_post_path %> 

HTML頁面後這裏是我的策略頁複印件

class ApplicationPolicy 
    attr_reader :user, :record 

    def initialize(user, record) 
    raise Pundit::NotAuthorizedError, "must be logged in" unless user 
    @user = user 
    @record = record 
    end 

    def index? 
    false 
    end 

    def show? 
    scope.where(:id => record.id).exists? 
    end 

    def create? 
    false 
    end 

    def new? 
    create? 
    end 

    def update? 
    false 
    end 

    def edit? 
    update? 
    end 

    def destroy? 
    false 
    end 

    def scope 
    Pundit.policy_scope!(user, record.class) 
    end 
end 

class PostPolicy < ApplicationPolicy 
    class Scope < Struct.new(:user, :scope) 
    def resolve 
     scope 
    end 
    end 
end 

我的用戶模型,我斯塔用色器件和我的職位模型LLED

class User < ActiveRecord::Base 
    attr_accessible :role, :published 

    def author? 
    role == 'author' 
    end 

    def editor? 
    role == 'editor' 
    end 
    # Include default devise modules. Others available are: 
    # :confirmable, :lockable, :timeoutable and :omniauthable 
    devise :database_authenticatable, :registerable, 
     :recoverable, :rememberable, :trackable, :validatable 

    # Setup accessible (or protected) attributes for your model 
    attr_accessible :email, :password, :password_confirmation, :remember_me 
    # attr_accessible :title, :body 
    has_many :posts, foreign_key: "author_id" 
end 


class Post < ActiveRecord::Base 
    attr_accessible :content, :title 
    belongs_to :author, class_name: "User" 

    def publish! 
    published = true 
    save! 
    end 
end 

,也是我的帖子控制器

對不起弄清這一點對我來說就像在乾草堆發現一針任何人都可以點我在正確的方向?

回答

-1

您簽署了LimeChat,因此我無法回答您的問題,添加到視圖中的邏輯表示,他們只應填充適用於應該訪問這些操作的用戶。所以你可以嘗試讓你的登錄用戶進行測試,一個編輯器,因爲現在理論上他們是唯一能夠看到這些按鈕的用戶。

0

很抱歉回覆舊帖子,但爲此,您的摧毀?策略自動爲false(在策略中沒有銷燬?因此,您將回退到ApplicationPolicy),因此無論用戶是誰,都不會創建刪除按鈕。