【问题标题】:expose_decorated is not working with posts variable. Why?expose_decorated 不适用于帖子变量。为什么?
【发布时间】:2016-08-21 16:31:38
【问题描述】:

我尝试在我的项目中使用 draper、decent_exposure 和 decent_decoration gem,但有些东西无法正常工作。这很奇怪,因为我只是从另一个项目中复制了这段代码。

我的控制器是:

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

【问题讨论】:

  • 如果我只使用带有代码expose :posts, -&gt; {Post.all} 的体面曝光,它可以正常工作,但这不是我想要的。

标签: ruby-on-rails draper decent-exposure


【解决方案1】:

我想通了。我没有工作,因为我使用的是 3.0.0 版本的体面曝光,而体面装饰与版本 >= 2.0 兼容。

我将体面曝光的版本更改为 2.3,它可以正常工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-12-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-08-06
    • 1970-01-01
    • 2016-08-25
    • 1970-01-01
    相关资源
    最近更新 更多