Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/ruby-on-rails-3/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 如何创建要与render一起使用的类';部分';,:收集_Ruby On Rails_Ruby On Rails 3 - Fatal编程技术网

Ruby on rails 如何创建要与render一起使用的类';部分';,:收集

Ruby on rails 如何创建要与render一起使用的类';部分';,:收集,ruby-on-rails,ruby-on-rails-3,Ruby On Rails,Ruby On Rails 3,我尝试创建包含枚举的ruby类 所以在DE视图中,我尝试使用render类,该类具有每个方法,并且应该返回为特定内容id构建的对象 下面是使用此代码的视图一些文件.haml . . . %table{:border => "0"} %thead %tr %td Files %td Views %td Comments %td Likes %tbody - render 'content_stats_row', :co

我尝试创建包含枚举的ruby类 所以在DE视图中,我尝试使用render类,该类具有每个方法,并且应该返回为特定内容id构建的对象

下面是使用此代码的视图一些文件.haml

.
.
.
%table{:border => "0"}
  %thead
    %tr
      %td Files
      %td Views
      %td Comments
      %td Likes 
  %tbody
    - render 'content_stats_row', :collection => @graphs.content_stats_table, :as => :row
.
.
.
这是我的@graphs

module FusionGraphs
  class ContentStatsTable
    include Enumerable

    def initialize(content_ids, start_date, end_date)
      @content_ids, @start_date, @end_date = content_ids, start_date, end_date 
    end

    def summarized_content
      @summarized_content ||= Hash[ Content.where(:id => @content_ids).value_of(:id, :name) ]
    end

    def summarized_comments
      @summarized_comments ||= Comment.where(:content_id => @content_ids)
                                  .where('date(created_at) between ? and ? ', @start_date, @end_date)
                                  .group(:content_id)
                                  .count
    end

    def summarized_views
      @summarized_views ||= View.where(:viewable_type => 'Content', :viewable_id => @content_ids)
                            .where('date(created_at) between ? and ? ', @start_date, @end_date)
                            .group(:viewable_id)
                            .count

    end

    def summarized_likes
      @summarized_likes ||= Like.where(:content_id => @content_ids)
                            .where('date(created_at) between ? and ? ', @start_date, @end_date)
                            .group(:content_id)
                            .count
    end

    def each
      @rows ||= @content_ids.map do |content_id|
              OpenStruct.new( :content_name => summarized_content[content_id],
                              :views => summarized_views[content_id] || 0,
                              :comments => summarized_comments[content_id] || 0,
                              :likes => summarized_likes[content_id] || 0
                            )
             end
    @rows.each {|row| yield row }
    end

  end
end
我无法从**呈现'content\u stats\u row',:collection=>graphs.content\u stats\u table,:as=>:row获得结果** 它不起作用
我做错了什么?

在haml视图文件中,您在渲染之前放置了(-)连字符,它应该是(=)相等的。

-render
替换为
=render
谢谢。我觉得自己像个白痴:(