csv_rails 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc CHANGED
@@ -1,6 +1,6 @@
1
1
  = CsvRails
2
2
 
3
- CsvRails provides a simple way of download csv in Rails 3(Now only 3.2.x).
3
+ CsvRails provides a simple way of download csv in Rails 3.
4
4
 
5
5
  == Install
6
6
 
@@ -36,10 +36,4 @@ If you want formatted created_at in the csv you should write like this
36
36
  end
37
37
  end
38
38
 
39
-
40
- == TODO
41
-
42
- - Support multi versions of rails.
43
-
44
-
45
39
  Copyright (c) 2012 yalab, released under the MIT license
@@ -10,7 +10,15 @@ module ActiveRecord
10
10
 
11
11
  module ClassMethods
12
12
  def to_csv(opts={})
13
- fields = opts.delete(:fields) || attribute_names
13
+ fields = if opts[:fields]
14
+ opts.delete(:fields)
15
+ elsif respond_to?(:attribute_names)
16
+ attribute_names
17
+ elsif self.is_a?(ActiveRecord::Relation)
18
+ @klass.new.attribute_names
19
+ else
20
+ new.attribute_names
21
+ end
14
22
  CSV.generate do |csv|
15
23
  csv << fields.map{|f|
16
24
  name = human_attribute_name(f)
@@ -1,3 +1,3 @@
1
1
  module CsvRails
2
- VERSION = "0.3.0"
2
+ VERSION = "0.4.0"
3
3
  end
@@ -1,13 +1,12 @@
1
1
  <!DOCTYPE html>
2
2
  <html>
3
3
  <head>
4
- <title>Dummy</title>
4
+ <title>CSV Download</title>
5
5
  <%= stylesheet_link_tag "application", :media => "all" %>
6
6
  <%= javascript_include_tag "application" %>
7
- <%= csrf_meta_tags %>
8
7
  </head>
9
8
  <body>
10
-
9
+ <%= Rails.version %>
11
10
  <%= yield %>
12
11
 
13
12
  </body>
@@ -1,2 +1,5 @@
1
1
  <h1>Users#index</h1>
2
2
  <p>Find me in app/views/users/index.html.erb</p>
3
+ <%= link_to '[Download(UTF-8)]', users_path(:format => 'csv') %>
4
+ &nbsp;&nbsp;
5
+ <%= link_to '[Download(SJIS)]', sjis_users_path(:format => 'csv') %>
@@ -45,12 +45,6 @@ module Dummy
45
45
  # in your app. As such, your models will need to explicitly whitelist or blacklist accessible
46
46
  # parameters by using an attr_accessible or attr_protected declaration.
47
47
  # config.active_record.whitelist_attributes = true
48
-
49
- # Enable the asset pipeline
50
- config.assets.enabled = true
51
-
52
- # Version of your assets, change this if you want to expire all your assets
53
- config.assets.version = '1.0'
54
48
  end
55
49
  end
56
50
 
@@ -22,16 +22,6 @@ Dummy::Application.configure do
22
22
  # Only use best-standards-support built into browsers
23
23
  config.action_dispatch.best_standards_support = :builtin
24
24
 
25
- # Raise exception on mass assignment protection for Active Record models
26
- config.active_record.mass_assignment_sanitizer = :strict
27
-
28
25
  # Log the query plan for queries taking more than this (works
29
26
  # with SQLite, MySQL, and PostgreSQL)
30
- config.active_record.auto_explain_threshold_in_seconds = 0.5
31
-
32
- # Do not compress assets
33
- config.assets.compress = false
34
-
35
- # Expands the lines which load the assets
36
- config.assets.debug = true
37
27
  end
@@ -29,9 +29,6 @@ Dummy::Application.configure do
29
29
  # ActionMailer::Base.deliveries array.
30
30
  config.action_mailer.delivery_method = :test
31
31
 
32
- # Raise exception on mass assignment protection for Active Record models
33
- config.active_record.mass_assignment_sanitizer = :strict
34
-
35
32
  # Print deprecation notices to the stderr
36
33
  config.active_support.deprecation = :stderr
37
34
  end
Binary file
@@ -1,81 +1,238 @@
1
- SQL (0.8ms)  SELECT name
1
+
2
+
3
+ Started GET "/" for 127.0.0.1 at 2012-03-25 13:17:13 +0900
4
+
5
+ ActionController::RoutingError (No route matches "/"):
6
+
7
+
8
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)
9
+
10
+
11
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:17:16 +0900
12
+ Processing by UsersController#index as HTML
13
+ SQL (0.6ms)  SELECT name
2
14
  FROM sqlite_master
3
15
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
4
16
  
5
- SQL (0.1ms) SELECT name
17
+ SQL (0.2ms) SELECT name
6
18
  FROM sqlite_master
7
19
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
8
- SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
9
- SQL (0.3ms) select sqlite_version(*)
10
20
  SQL (0.1ms)  SELECT name
11
21
  FROM sqlite_master
12
22
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
13
- 
14
- SQL (36.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "age" integer, "secret" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
15
- SQL (0.4ms)  SELECT name
16
- FROM sqlite_master
17
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
18
- 
19
- SQL (12.7ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
20
- SQL (0.1ms) PRAGMA index_list("schema_migrations")
21
- SQL (14.8ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
22
- SQL (0.5ms)  SELECT name
23
- FROM sqlite_master
24
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
25
- 
26
- SQL (0.2ms) SELECT version FROM "schema_migrations"
27
- SQL (12.1ms) INSERT INTO "schema_migrations" (version) VALUES ('20120323112247')
28
- SQL (0.5ms)  SELECT name
29
- FROM sqlite_master
30
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
31
23
  
32
24
  SQL (0.1ms) SELECT name
33
25
  FROM sqlite_master
34
26
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
35
- SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
36
- SQL (0.2ms) select sqlite_version(*)
37
27
  SQL (0.1ms)  SELECT name
38
28
  FROM sqlite_master
39
29
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
40
30
  
41
- SQL (36.5ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "age" integer, "secret" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
42
- SQL (0.2ms)  SELECT name
43
- FROM sqlite_master
44
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
45
- 
46
- SQL (12.1ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
47
- SQL (0.1ms) PRAGMA index_list("schema_migrations")
48
- SQL (15.2ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
49
- SQL (0.3ms)  SELECT name
31
+ SQL (0.1ms) SELECT name
50
32
  FROM sqlite_master
51
33
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
52
- 
53
- SQL (0.1ms) SELECT version FROM "schema_migrations"
54
- SQL (11.8ms) INSERT INTO "schema_migrations" (version) VALUES ('20120323112247')
55
- SQL (0.6ms)  SELECT name
34
+ SQL (0.2ms)  SELECT name
56
35
  FROM sqlite_master
57
36
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
58
37
  
59
38
  SQL (0.1ms) SELECT name
60
39
  FROM sqlite_master
61
40
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
62
- SQL (0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations"
63
- SQL (0.2ms) select sqlite_version(*)
64
- SQL (0.1ms)  SELECT name
65
- FROM sqlite_master
66
- WHERE type = 'table' AND NOT name = 'sqlite_sequence'
67
- 
68
- SQL (20.8ms) CREATE TABLE "users" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "name" varchar(255), "age" integer, "secret" varchar(255), "created_at" datetime NOT NULL, "updated_at" datetime NOT NULL)
69
- SQL (0.4ms)  SELECT name
41
+ Rendered users/index.html.erb within layouts/application (16.7ms)
42
+ Completed 500 Internal Server Error in 44ms
43
+
44
+ ActionView::Template::Error (undefined local variable or method `csrf_meta_tags' for #<#<Class:0xa638904>:0xa637b94>):
45
+ 4: <title>Dummy</title>
46
+ 5: <%= stylesheet_link_tag "application", :media => "all" %>
47
+ 6: <%= javascript_include_tag "application" %>
48
+ 7: <%= csrf_meta_tags %>
49
+ 8: </head>
50
+ 9: <body>
51
+ 10:
52
+ app/views/layouts/application.html.erb:7:in `_app_views_layouts_application_html_erb___161023209_87143500__417950673'
53
+ app/controllers/users_controller.rb:4:in `index'
54
+
55
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/_trace.erb (2.7ms)
56
+ SQL (0.3ms)  SELECT name
70
57
  FROM sqlite_master
71
58
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
72
59
  
73
- SQL (12.5ms) CREATE TABLE "schema_migrations" ("version" varchar(255) NOT NULL)
74
- SQL (0.1ms) PRAGMA index_list("schema_migrations")
75
- SQL (14.5ms) CREATE UNIQUE INDEX "unique_schema_migrations" ON "schema_migrations" ("version")
76
- SQL (0.3ms)  SELECT name
60
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (3.4ms)
61
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/template_error.erb within rescues/layout (12.8ms)
62
+
63
+
64
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:17:29 +0900
65
+ Processing by UsersController#index as HTML
66
+ Rendered users/index.html.erb within layouts/application (1.3ms)
67
+ Completed 200 OK in 6ms (Views: 4.7ms | ActiveRecord: 1.9ms)
68
+
69
+
70
+ Started GET "/stylesheets/application.css" for 127.0.0.1 at 2012-03-25 13:17:29 +0900
71
+
72
+ ActionController::RoutingError (No route matches "/stylesheets/application.css"):
73
+
74
+
75
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
76
+
77
+
78
+ Started GET "/javascripts/application.js" for 127.0.0.1 at 2012-03-25 13:17:29 +0900
79
+
80
+ ActionController::RoutingError (No route matches "/javascripts/application.js"):
81
+
82
+
83
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (24.6ms)
84
+ SQL (0.2ms)  SELECT name
77
85
  FROM sqlite_master
78
86
  WHERE type = 'table' AND NOT name = 'sqlite_sequence'
79
87
  
80
- SQL (0.2ms) SELECT version FROM "schema_migrations"
81
- SQL (12.6ms) INSERT INTO "schema_migrations" (version) VALUES ('20120323112247')
88
+ AREL (0.4ms) INSERT INTO "users" ("name", "age", "secret", "created_at", "updated_at") VALUES ('yalab', 20, 'hoge', '2012-03-25 04:17:59.258041', '2012-03-25 04:17:59.258041')
89
+
90
+
91
+ Started GET "/users.csv" for 127.0.0.1 at 2012-03-25 13:19:30 +0900
92
+ Processing by UsersController#index as CSV
93
+ User Load (0.8ms) SELECT "users".* FROM "users"
94
+ Rendered text template (0.0ms)
95
+ Sent data (2.1ms)
96
+ Completed 200 OK in 43ms (Views: 40.8ms | ActiveRecord: 0.0ms)
97
+
98
+
99
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:20:34 +0900
100
+ Processing by UsersController#index as HTML
101
+ Rendered users/index.html.erb within layouts/application (1.3ms)
102
+ Completed 200 OK in 6ms (Views: 4.4ms | ActiveRecord: 0.0ms)
103
+
104
+
105
+ Started GET "/stylesheets/application.css" for 127.0.0.1 at 2012-03-25 13:20:34 +0900
106
+
107
+ ActionController::RoutingError (No route matches "/stylesheets/application.css"):
108
+
109
+
110
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.3ms)
111
+
112
+
113
+ Started GET "/javascripts/application.js" for 127.0.0.1 at 2012-03-25 13:20:34 +0900
114
+
115
+ ActionController::RoutingError (No route matches "/javascripts/application.js"):
116
+
117
+
118
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.4ms)
119
+
120
+
121
+ Started GET "/users.csv" for 127.0.0.1 at 2012-03-25 13:20:37 +0900
122
+ Processing by UsersController#index as CSV
123
+ User Load (0.5ms) SELECT "users".* FROM "users"
124
+ Rendered text template (0.0ms)
125
+ Sent data (2.9ms)
126
+ Completed 200 OK in 21ms (Views: 19.3ms | ActiveRecord: 0.0ms)
127
+
128
+
129
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:21:58 +0900
130
+ Processing by UsersController#index as HTML
131
+ Rendered users/index.html.erb within layouts/application (1.9ms)
132
+ Completed 200 OK in 7ms (Views: 5.0ms | ActiveRecord: 0.0ms)
133
+
134
+
135
+ Started GET "/stylesheets/application.css" for 127.0.0.1 at 2012-03-25 13:21:58 +0900
136
+
137
+ ActionController::RoutingError (No route matches "/stylesheets/application.css"):
138
+
139
+
140
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
141
+
142
+
143
+ Started GET "/javascripts/application.js" for 127.0.0.1 at 2012-03-25 13:21:58 +0900
144
+
145
+ ActionController::RoutingError (No route matches "/javascripts/application.js"):
146
+
147
+
148
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.1ms)
149
+
150
+
151
+ Started GET "/users.csv" for 127.0.0.1 at 2012-03-25 13:21:59 +0900
152
+ Processing by UsersController#index as CSV
153
+ User Load (0.7ms) SELECT "users".* FROM "users"
154
+ Rendered text template (0.0ms)
155
+ Sent data (3.2ms)
156
+ Completed 200 OK in 28ms (Views: 25.9ms | ActiveRecord: 0.0ms)
157
+
158
+
159
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:23:11 +0900
160
+ Processing by UsersController#index as HTML
161
+ Rendered users/index.html.erb within layouts/application (1.8ms)
162
+ Completed 200 OK in 7ms (Views: 4.8ms | ActiveRecord: 0.0ms)
163
+
164
+
165
+ Started GET "/stylesheets/application.css" for 127.0.0.1 at 2012-03-25 13:23:11 +0900
166
+
167
+ ActionController::RoutingError (No route matches "/stylesheets/application.css"):
168
+
169
+
170
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.9ms)
171
+
172
+
173
+ Started GET "/javascripts/application.js" for 127.0.0.1 at 2012-03-25 13:23:11 +0900
174
+
175
+ ActionController::RoutingError (No route matches "/javascripts/application.js"):
176
+
177
+
178
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.6ms)
179
+
180
+
181
+ Started GET "/users.csv" for 127.0.0.1 at 2012-03-25 13:23:12 +0900
182
+ Processing by UsersController#index as CSV
183
+ User Load (0.6ms) SELECT "users".* FROM "users"
184
+ Rendered text template (0.0ms)
185
+ Sent data (3.3ms)
186
+ Completed 200 OK in 22ms (Views: 20.1ms | ActiveRecord: 0.0ms)
187
+
188
+
189
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:24:44 +0900
190
+ Processing by UsersController#index as HTML
191
+ Rendered users/index.html.erb within layouts/application (2.0ms)
192
+ Completed 200 OK in 6ms (Views: 4.8ms | ActiveRecord: 0.0ms)
193
+
194
+
195
+ Started GET "/stylesheets/application.css" for 127.0.0.1 at 2012-03-25 13:24:44 +0900
196
+
197
+ ActionController::RoutingError (No route matches "/stylesheets/application.css"):
198
+
199
+
200
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
201
+
202
+
203
+ Started GET "/javascripts/application.js" for 127.0.0.1 at 2012-03-25 13:24:44 +0900
204
+
205
+ ActionController::RoutingError (No route matches "/javascripts/application.js"):
206
+
207
+
208
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.2ms)
209
+
210
+
211
+ Started GET "/users" for 127.0.0.1 at 2012-03-25 13:24:52 +0900
212
+ Processing by UsersController#index as HTML
213
+ Rendered users/index.html.erb within layouts/application (2.3ms)
214
+ Completed 200 OK in 9ms (Views: 6.5ms | ActiveRecord: 0.0ms)
215
+
216
+
217
+ Started GET "/stylesheets/application.css" for 127.0.0.1 at 2012-03-25 13:24:53 +0900
218
+
219
+ ActionController::RoutingError (No route matches "/stylesheets/application.css"):
220
+
221
+
222
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (1.0ms)
223
+
224
+
225
+ Started GET "/javascripts/application.js" for 127.0.0.1 at 2012-03-25 13:24:53 +0900
226
+
227
+ ActionController::RoutingError (No route matches "/javascripts/application.js"):
228
+
229
+
230
+ Rendered /home/yalab/project/csv_rails/.bundle/ruby/1.9.1/gems/actionpack-3.0.12/lib/action_dispatch/middleware/templates/rescues/routing_error.erb within rescues/layout (0.9ms)
231
+
232
+
233
+ Started GET "/users/sjis.csv" for 127.0.0.1 at 2012-03-25 13:24:54 +0900
234
+ Processing by UsersController#sjis as CSV
235
+ User Load (0.6ms) SELECT "users".* FROM "users"
236
+ Rendered text template (0.0ms)
237
+ Sent data (1.9ms)
238
+ Completed 200 OK in 22ms (Views: 19.6ms | ActiveRecord: 0.6ms)