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