rows_controller 2.1.0 → 2.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +8 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/.travis.yml +22 -0
- data/Appraisals +21 -0
- data/Gemfile +14 -0
- data/Gemfile.lock +169 -0
- data/MIT-LICENSE +1 -1
- data/NOTES +87 -0
- data/README.md +1 -1
- data/Rakefile +1 -19
- data/app/controllers/.keep +0 -0
- data/app/views/.keep +0 -0
- data/bin/rails +12 -0
- data/gemfiles/rails_4.2.0.gemfile +13 -0
- data/gemfiles/rails_4.2.4.gemfile +13 -0
- data/gemfiles/rails_5.1.gemfile +17 -0
- data/gemfiles/rails_5.2.gemfile +17 -0
- data/lib/rows/version.rb +1 -1
- data/rows_controller.gemspec +25 -0
- data/script/rails +8 -0
- data/test/.watchr +61 -0
- data/test/controllers/order/items_controller_test.rb +64 -0
- data/test/controllers/orders_test.rb +83 -0
- data/test/controllers/rows_controller_test.rb +52 -0
- data/test/controllers/rows_ext_controller_test.rb +25 -0
- data/test/dummy3/Rakefile +6 -0
- data/test/dummy3/app/controllers/application_controller.rb +3 -0
- data/test/dummy3/app/controllers/order/items_controller.rb +8 -0
- data/test/dummy3/app/controllers/orders_controller.rb +8 -0
- data/test/dummy3/app/models/order.rb +14 -0
- data/test/dummy3/app/models/order/item.rb +4 -0
- data/test/dummy3/app/views/layouts/application.html.erb +12 -0
- data/test/dummy3/app/views/order/items/_form.html.erb +8 -0
- data/test/dummy3/app/views/orders/_form.html.erb +8 -0
- data/test/dummy3/config.ru +4 -0
- data/test/dummy3/config/application.rb +58 -0
- data/test/dummy3/config/boot.rb +10 -0
- data/test/dummy3/config/database.yml +25 -0
- data/test/dummy3/config/environment.rb +5 -0
- data/test/dummy3/config/environments/development.rb +37 -0
- data/test/dummy3/config/environments/production.rb +67 -0
- data/test/dummy3/config/environments/test.rb +37 -0
- data/test/dummy3/config/initializers/secret_token.rb +7 -0
- data/test/dummy3/config/initializers/session_store.rb +8 -0
- data/test/dummy3/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy3/config/routes.rb +9 -0
- data/test/dummy3/db/migrate/001_create_orders.rb +9 -0
- data/test/dummy3/db/migrate/002_create_order_items.rb +9 -0
- data/test/dummy3/db/schema.rb +28 -0
- data/test/dummy3/script/rails +6 -0
- data/test/dummy4/Rakefile +6 -0
- data/test/dummy4/app/controllers/application_controller.rb +3 -0
- data/test/dummy4/app/controllers/order/items_controller.rb +8 -0
- data/test/dummy4/app/controllers/orders_controller.rb +8 -0
- data/test/dummy4/app/models/order.rb +13 -0
- data/test/dummy4/app/models/order/item.rb +2 -0
- data/test/dummy4/app/views/layouts/application.html.erb +12 -0
- data/test/dummy4/app/views/order/items/_form.html.erb +8 -0
- data/test/dummy4/app/views/orders/_form.html.erb +8 -0
- data/test/dummy4/bin/bundle +3 -0
- data/test/dummy4/bin/rails +4 -0
- data/test/dummy4/bin/rake +4 -0
- data/test/dummy4/bin/setup +29 -0
- data/test/dummy4/config.ru +4 -0
- data/test/dummy4/config/application.rb +25 -0
- data/test/dummy4/config/boot.rb +5 -0
- data/test/dummy4/config/database.yml +25 -0
- data/test/dummy4/config/environment.rb +5 -0
- data/test/dummy4/config/environments/development.rb +41 -0
- data/test/dummy4/config/environments/production.rb +79 -0
- data/test/dummy4/config/environments/test.rb +42 -0
- data/test/dummy4/config/initializers/cookies_serializer.rb +3 -0
- data/test/dummy4/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy4/config/initializers/session_store.rb +3 -0
- data/test/dummy4/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy4/config/routes.rb +9 -0
- data/test/dummy4/config/secrets.yml +22 -0
- data/test/dummy4/db/migrate/001_create_orders.rb +9 -0
- data/test/dummy4/db/migrate/002_create_order_items.rb +9 -0
- data/test/dummy4/db/schema.rb +28 -0
- data/test/dummy4/log/.keep +0 -0
- data/test/dummy5/Rakefile +6 -0
- data/test/dummy5/app/controllers/application_controller.rb +3 -0
- data/test/dummy5/app/controllers/order/items_controller.rb +8 -0
- data/test/dummy5/app/controllers/orders_controller.rb +8 -0
- data/test/dummy5/app/models/application_record.rb +3 -0
- data/test/dummy5/app/models/order.rb +12 -0
- data/test/dummy5/app/models/order/item.rb +2 -0
- data/test/dummy5/app/views/layouts/application.html.erb +12 -0
- data/test/dummy5/app/views/order/items/_form.html.erb +8 -0
- data/test/dummy5/app/views/orders/_form.html.erb +8 -0
- data/test/dummy5/bin/rails +9 -0
- data/test/dummy5/config.ru +5 -0
- data/test/dummy5/config/application.rb +19 -0
- data/test/dummy5/config/boot.rb +6 -0
- data/test/dummy5/config/database.yml +25 -0
- data/test/dummy5/config/environment.rb +5 -0
- data/test/dummy5/config/environments/test.rb +42 -0
- data/test/dummy5/config/routes.rb +9 -0
- data/test/dummy5/config/secrets.yml +32 -0
- data/test/dummy5/config/spring.rb +6 -0
- data/test/dummy5/db/migrate/001_create_orders.rb +9 -0
- data/test/dummy5/db/migrate/002_create_order_items.rb +9 -0
- data/test/dummy5/db/schema.rb +27 -0
- data/test/dummy5/log/.keep +0 -0
- data/test/fixtures/order/items.yml +5 -0
- data/test/fixtures/orders.yml +5 -0
- data/test/test_helper.rb +31 -0
- metadata +231 -12
- data/app/controllers/rows_controller.rb.bak +0 -88
- data/lib/rows/resources.rb.bak +0 -80
@@ -1,88 +0,0 @@
|
|
1
|
-
require 'rows/resources'
|
2
|
-
require 'rows/model'
|
3
|
-
require 'rows/utils'
|
4
|
-
|
5
|
-
class RowsController < ApplicationController
|
6
|
-
helper_method :set_resource, :set_resources, :resource, :resources
|
7
|
-
helper_method :resource_columns, :resource_format
|
8
|
-
helper_method :model_class, :model_name
|
9
|
-
helper_method :model_symbol, :model_symbol_plural
|
10
|
-
|
11
|
-
include Rows::Model
|
12
|
-
include Rows::Resources
|
13
|
-
include Rows::Utils
|
14
|
-
|
15
|
-
def self.model_class(model_class = nil)
|
16
|
-
@_model_class ||= nil
|
17
|
-
@_model_class = model_class unless model_class.nil?
|
18
|
-
@_model_class
|
19
|
-
end
|
20
|
-
|
21
|
-
# GET /:resources[.json]
|
22
|
-
def index
|
23
|
-
set_resources
|
24
|
-
end
|
25
|
-
|
26
|
-
# GET /:resource/:id[.json]
|
27
|
-
def show
|
28
|
-
set_resource
|
29
|
-
end
|
30
|
-
|
31
|
-
# GET /:resource/new
|
32
|
-
def new
|
33
|
-
resource_new
|
34
|
-
end
|
35
|
-
|
36
|
-
# GET /:resource/:id/edit
|
37
|
-
def edit
|
38
|
-
set_resource
|
39
|
-
end
|
40
|
-
|
41
|
-
# POST /:resources[.json]
|
42
|
-
def create
|
43
|
-
create_update(:resource_create, 'created')
|
44
|
-
end
|
45
|
-
|
46
|
-
# PATCH/PUT /:resources/:id[.json]
|
47
|
-
def update
|
48
|
-
set_resource
|
49
|
-
create_update(:resource_update, 'updated')
|
50
|
-
end
|
51
|
-
|
52
|
-
# DELETE /:resources/:id[.json]
|
53
|
-
def destroy
|
54
|
-
set_resource
|
55
|
-
resource_destroy
|
56
|
-
flash[:notice] = t('ui.destroyed', model: model_name).html_safe unless request.xhr?
|
57
|
-
respond_to do |format|
|
58
|
-
format.html { redirect_to action: :index }
|
59
|
-
format.js { render template: 'rows/destroy', layout: false }
|
60
|
-
format.json { head :no_content }
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
private
|
65
|
-
def create_update(which, msg)
|
66
|
-
respond_to do |format|
|
67
|
-
if self.send(which)
|
68
|
-
format.html {
|
69
|
-
flash[:notice] = t(msg, scope: :ui, model: model_name,
|
70
|
-
default: "%{model} was successfully #{msg}.").html_safe
|
71
|
-
if params[:commit] == 'OK'
|
72
|
-
redirect_to action: :index
|
73
|
-
else
|
74
|
-
redirect_to action: 'edit', id: resource.id
|
75
|
-
end
|
76
|
-
}
|
77
|
-
format.json { render action: 'show',
|
78
|
-
status: msg == 'created' ? :created : :ok,
|
79
|
-
location: resource }
|
80
|
-
else ## failed
|
81
|
-
format.html { render action: msg == 'created' ? :new : :edit }
|
82
|
-
format.json { render json: resource.errors,
|
83
|
-
status: :unprocessable_entity }
|
84
|
-
end
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
end
|
data/lib/rows/resources.rb.bak
DELETED
@@ -1,80 +0,0 @@
|
|
1
|
-
module Rows::Resources
|
2
|
-
|
3
|
-
def set_resources(rows = nil)
|
4
|
-
rows ||= model_class.all
|
5
|
-
instance_variable_set("@#{model_symbol_plural}", rows)
|
6
|
-
@rows = rows
|
7
|
-
end
|
8
|
-
|
9
|
-
def set_resource(row = nil)
|
10
|
-
row ||= model_class.find_by_id(params[:id].to_i)
|
11
|
-
instance_variable_set("@#{model_symbol}", row)
|
12
|
-
@row = row
|
13
|
-
end
|
14
|
-
|
15
|
-
def resources
|
16
|
-
@rows ||= set_resources
|
17
|
-
end
|
18
|
-
|
19
|
-
def resource
|
20
|
-
@row ||= set_resource
|
21
|
-
end
|
22
|
-
|
23
|
-
private
|
24
|
-
# low level resource methods
|
25
|
-
# can be monkey patched
|
26
|
-
def resource_new
|
27
|
-
if params[model_symbol]
|
28
|
-
set_resource model_class.new(resource_params)
|
29
|
-
else
|
30
|
-
set_resource model_class.new
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
def resource_create
|
35
|
-
resource_new
|
36
|
-
resource.save
|
37
|
-
end
|
38
|
-
|
39
|
-
def resource_update
|
40
|
-
if Rails::VERSION::MAJOR >= 4
|
41
|
-
return true unless params[model_symbol]
|
42
|
-
resource.update(resource_params)
|
43
|
-
else
|
44
|
-
resource.update_attributes(resource_params)
|
45
|
-
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def resource_destroy
|
49
|
-
resource.destroy
|
50
|
-
end
|
51
|
-
|
52
|
-
def resource_columns
|
53
|
-
return model_class.column_headers if model_class.respond_to?(:column_headers)
|
54
|
-
return ['to_s'] unless model_class.respond_to?(:content_columns)
|
55
|
-
['id'] + model_class.content_columns.collect{|c| c.name }
|
56
|
-
end
|
57
|
-
|
58
|
-
def resource_whitelist
|
59
|
-
raise "RowsController requires private method 'resource_whitelist' in controller <#{params[:controller]}>"
|
60
|
-
end
|
61
|
-
|
62
|
-
# Never trust parameters from the scary internet, only allow the white list through.
|
63
|
-
def resource_params
|
64
|
-
permits = resource_whitelist
|
65
|
-
if params.respond_to?(:require)
|
66
|
-
params.require(model_symbol).permit(permits)
|
67
|
-
else
|
68
|
-
pars = params[model_symbol] || {}
|
69
|
-
pars.keys.each { |x|
|
70
|
-
x = x.to_sym
|
71
|
-
unless permits.include?(x) || permits.include?({x => []})
|
72
|
-
pars.delete(x)
|
73
|
-
p "** WARNING: model <#{model_name}> dropping params <#{x}>"
|
74
|
-
end
|
75
|
-
}
|
76
|
-
pars
|
77
|
-
end
|
78
|
-
end
|
79
|
-
|
80
|
-
end
|