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}'它可以正常工作,但那不是我要找的。 –