0

MongoDB から csv にエクスポートすると、現在の i18n ロケールが取得されます。これを除外することはできますか?

{"sv"=>"hejsan"}

これだけにしてほしいhejsan

Participant.rb (モデル)

class Participant < Model
   ...
    def self.to_csv(options = {})
      CSV.generate(options) do |csv|
        csv << Participant.fields.keys
        all.each do |participant|
          csv << participant.attributes.values_at(*column_names)
        end
      end
   end
end

Model.rb (モデル)

class Model
    include Mongoid::Document
    def self.column_names
    self.fields.collect { |field| field[0] }
    end
end

コントローラ

def index
    @participants = Participant.all

    respond_to do |format|
      format.html # index.html.erb
      format.json { render json: @participants }
      format.csv { send_data @participants.to_csv }
      format.xls
    end
  end
4

0 に答える 0