Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # Model
- def self.to_csv(data, options = {})
- desired_columns = ["id", "name", "phone", "email", "created_at"]
- CSV.generate(options) do |csv|
- csv << desired_columns
- data.each do |u|
- csv << u.attributes.values_at(*desired_columns)
- end
- end
- end
- # Controller
- def index
- params = filter_params
- users= UserServices.fetch_data(params)
- @users = users.paginate(:page => params[:page], :per_page => 50)
- respond_to do |format|
- format.html
- format.csv { send_data UserServices.to_csv(users) }
- end
- end
- # View
- %form{method: :GET}
- .small-4.columns
- .small-6.columns
- %input.button.small{:type => "submit", :value => "Thực hiện"}
- .small-6.columns
- =link_to 'Export', user_index_path(format: "csv"), class: 'button small', id: 'user-export'
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement