Cómo crear una clase para usar con render 'some_partial',: colección

I try create ruby class with included Enumarable So insode view I try render class which has cada method and should return object builded for specific content_id

Here is view which use this code some_file.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
.
.
.

Here is my class for @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

I cant get results from ** render 'content_stats_row', :collection => graphs.content_stats_table, :as => :row ** It is not working What I'm doing wrong?

preguntado el 28 de agosto de 12 a las 12:08

reemplazar - render con = render -

Thanks. I feel like an idiot :( -

1 Respuestas

In your haml view file you placed (-)hyphen before render, it should be (=) equal.

Respondido 28 ago 12, 12:08

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.