2016-08-21 58 views
0

我尝试在我的项目中使用draper,decent_exposure和decent_decoration gems,但某些功能无法正常工作。这很奇怪,因为我刚刚从antoher项目中复制了这些代码。expose_decorated与posts变量不兼容。为什么?

我的控制器:

class PostsController < ApplicationController 

    expose_decorated(:post) 
    expose_decorated(:posts) 

    def create 
    if post.save 
     redirect_to post_path(post) 
    else 
     render :new 
    end 
    end 

    def update 
    if post.update(post_params) 
     redirect_to post_path(post) 
    else 
     render :edit 
    end 
    end 

    def destroy 
    post.destroy 
    redirect_to posts_path 
    end 

    private 

    def post_params 
     params.require(:post).permit(:title, :content) 
    end 

end 

,这里是索引视图

%h1 Blog 

- posts.each do |post| 
    %p= post.title 
    %p= post.content 

,我得到这个错误:

undefined method `map' for #<Post:0x007f7df88dcca0> 
Did you mean? tap 
+0

如果我只用decent_exposure和代码'expose:posts, - > {Post.all}'它可以正常工作,但那不是我要找的。 –

回答

0

我想通了。我没有工作,因为我使用的是decent_exposure 3.0.0版本,而decent_decoration与版本> = 2.0兼容。

我将decent_exposure的版本更改为2.3,它的工作原理应该如此。

相关问题