0
當試圖在軌導出CSV文件,我得到這些值僅CSV出口在軌
`#<User:0x007f4a41859980> #<User:0x007f4a41835c88>
我控制器文件ps4_controller.rb
def csv_export
@users = User.order(created_at: :desc)
respond_to do |format|
format.html
format.csv { render text: @users.to_csv }
format.xls { render text: @users.to_csv(col_sep: "\t") }
end
end
模型文件ps4.rb
class Ps4 < ActiveRecord::Base
attr_accessible :username, :email, :school, :batch
def self.to_csv(users)
CSV.generate do |csv|
csv << column_names
users.each do |ps4|
csv << ps4.attributes.values_at(*column_names)
end
end
end
end
查看文件csv_export.xls.rb
<table>
<thead>
<tr>
<th>Username</th>
<th>Email</th>
<th>School</th>
<th>Batch</th>
</tr>
</thead>
<tbody>
<% @users.each do |user| %>
<tr>
<td><%= user.username %></td>
<td><%= user.email %></td>
<td><%= user.school %></td>
<td><%= user.batch %></td>
</tr>
<% end %>
</tbody>
</table>
有人可以幫忙嗎?