2016-08-02 54 views
1

我需要以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 

的問題是該網頁重定向到索引page.But它並沒有在指數page.It顯示記錄顯示空白指數page.I不知道如何解決這個問題。

+0

您需要在url結尾添加.csv。例如/customers.csv –

回答

0

試試這個。

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

希望它能幫上忙。