rails显示索引页面中的记录列表

时间:2016-08-02 10:45:01

标签: ruby-on-rails csv

我需要以csv格式在索引页面中显示所有客户。

 def self.customer_list
    CSV.generate do |csv|
      csv << column_names
      all.each do |customer_detail|
      csv << customer_detail.attributes.values_at(*column_names)
        end
      end
    end
 end


 def index
    @customer_details = CustomerDetail.all
    respond_to do |format|
      format.html
      format.csv { render text: @customer_details.customer_list }
    end
  end

问题是页面正在重定向到索引页面。但它没有显示索引页面中的记录。它显示一个空的索引页面。我不知道如何解决这个问题。

1 个答案:

答案 0 :(得分:0)

试试这个。

 def index
    @customer_details = CustomerDetail.customer_list
    respond_to do |format|
      format.html
      format.csv { render text: @customer_details }
    end
  end

希望它会有所帮助。

相关问题