robot_catcher 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (92) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +34 -0
  3. data/lib/robot_catcher/helpers.rb +164 -0
  4. data/lib/robot_catcher/models.rb +55 -0
  5. data/lib/robot_catcher/version.rb +3 -0
  6. data/lib/robot_catcher.rb +5 -0
  7. data/lib/tasks/robot_catcher_tasks.rake +4 -0
  8. data/test/dummy/README.rdoc +28 -0
  9. data/test/dummy/Rakefile +6 -0
  10. data/test/dummy/app/assets/javascripts/application.js +13 -0
  11. data/test/dummy/app/assets/javascripts/articles.js +2 -0
  12. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  13. data/test/dummy/app/assets/stylesheets/articles.css +4 -0
  14. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  15. data/test/dummy/app/controllers/application_controller.rb +5 -0
  16. data/test/dummy/app/controllers/articles_controller.rb +68 -0
  17. data/test/dummy/app/helpers/application_helper.rb +2 -0
  18. data/test/dummy/app/helpers/articles_helper.rb +2 -0
  19. data/test/dummy/app/models/article.rb +3 -0
  20. data/test/dummy/app/views/articles/_form.html.erb +27 -0
  21. data/test/dummy/app/views/articles/edit.html.erb +6 -0
  22. data/test/dummy/app/views/articles/index.html.erb +29 -0
  23. data/test/dummy/app/views/articles/new.html.erb +5 -0
  24. data/test/dummy/app/views/articles/show.html.erb +14 -0
  25. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  26. data/test/dummy/bin/bundle +3 -0
  27. data/test/dummy/bin/rails +4 -0
  28. data/test/dummy/bin/rake +4 -0
  29. data/test/dummy/bin/setup +29 -0
  30. data/test/dummy/config/application.rb +26 -0
  31. data/test/dummy/config/boot.rb +5 -0
  32. data/test/dummy/config/database.yml +25 -0
  33. data/test/dummy/config/environment.rb +5 -0
  34. data/test/dummy/config/environments/development.rb +41 -0
  35. data/test/dummy/config/environments/production.rb +79 -0
  36. data/test/dummy/config/environments/test.rb +42 -0
  37. data/test/dummy/config/initializers/assets.rb +11 -0
  38. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  39. data/test/dummy/config/initializers/cookies_serializer.rb +3 -0
  40. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  41. data/test/dummy/config/initializers/inflections.rb +16 -0
  42. data/test/dummy/config/initializers/mime_types.rb +4 -0
  43. data/test/dummy/config/initializers/session_store.rb +3 -0
  44. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  45. data/test/dummy/config/locales/en.yml +23 -0
  46. data/test/dummy/config/routes.rb +57 -0
  47. data/test/dummy/config/secrets.yml +22 -0
  48. data/test/dummy/config.ru +4 -0
  49. data/test/dummy/db/development.sqlite3 +0 -0
  50. data/test/dummy/db/migrate/20151108205618_create_articles.rb +10 -0
  51. data/test/dummy/db/schema.rb +23 -0
  52. data/test/dummy/log/development.log +3471 -0
  53. data/test/dummy/log/localdev.log +0 -0
  54. data/test/dummy/public/404.html +67 -0
  55. data/test/dummy/public/422.html +67 -0
  56. data/test/dummy/public/500.html +66 -0
  57. data/test/dummy/public/favicon.ico +0 -0
  58. data/test/dummy/test/controllers/articles_controller_test.rb +49 -0
  59. data/test/dummy/test/fixtures/articles.yml +9 -0
  60. data/test/dummy/test/models/article_test.rb +7 -0
  61. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/--2G_c3lCtePsllqkgTSDvk0ws9adbGDQcRvLN_EQ88.cache +1 -0
  62. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/-OJUBxdS-bG4zgi-HNiw9Xlp2QIvHoW8uLDPD75uXpI.cache +2 -0
  63. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/5Lly_CA8DZvPhQV2jDQx-Y6P_y3Ygra9t5jfSlGhHDA.cache +2 -0
  64. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/6uLqoeIeLD2NhPQtj3DYvLFYpEraf1qU147qnysVO6g.cache +1 -0
  65. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/9DpUR_fC14S52b3zrRiKeYjtEArvbqKqmYmCMGHiD9k.cache +0 -0
  66. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/DmmfrCpXtt74Hr6NO54lxyOCDv6klnDyBqeDFR7oDU8.cache +2 -0
  67. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/ELhioJOkik-XcPi3xdXhtHPxP_N8Z1sOLprd6_6TgLY.cache +0 -0
  68. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/JOBnsEqvVtSYuP7X3CVBY5Dxm8D_TINDaEumd2pwmkE.cache +1 -0
  69. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/OI6uxGcnsKavdWTtwDAasU3wPx8QXhzBgV0X2n1KjMQ.cache +2 -0
  70. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/UV1QownSHK65LSLEBMZmSb9Gi-dyrL7sk8uw0slVYEc.cache +1 -0
  71. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/VWPIp3E8NJGBTg9eyT0mbVqhCyhZ1UQzQhIde-3joig.cache +0 -0
  72. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/WQeBW4dfEsVuZ8eNRzY3TghX-GvNZYZy_VCJ42fqMM4.cache +1 -0
  73. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/_xcIdFV-At2pOKyIP31prJqJzCsmdsuoYlkC1DB2jDQ.cache +2 -0
  74. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/aS4gFox4Lh7GJYDZIrtGDgdpp56SlZYzEOdAVy6iSC0.cache +1 -0
  75. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/dphXxQV1ZyMzvKy0tXw9loofG0G8_4MC_ZXSE_eHnFI.cache +2 -0
  76. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/fkqQtAYuWFbb3cJ_DYZg-rtZpbHzWUyEut5YrxkEBOI.cache +0 -0
  77. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/hZi1k6tpxxCGYxRe7zY74ItcOI8gZrREOpGuA8JSpGg.cache +2 -0
  78. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/mLUBzNlQGEI7HKRueSOU69pwu4qJb0dgVLB8yjE6Kr4.cache +1 -0
  79. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/mibJePh9DmzCatUn-6ukNUFR9SygbjuaunJ9JPtwMD0.cache +0 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/pEhaat2KBd5SrT7szC_8R1_6hK17FTpvoRFkmCRSD3M.cache +2 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/pyh8QRGkl9emfRSb4iUUwm_Bta21AwFIzZKueTu30W4.cache +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/qvll1qPabMn6TTkpuGOnx99Zg9gsM7t8pp2T63wFYKg.cache +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/rNpn7wAAWvFg9ecDT_imL7EYAYHTO17CUnJLmprWzdg.cache +1 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/v5edzu0SjVPbdCoXthlLmNhOVlForWZxZFcuObvVPzk.cache +1 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/wG_whueNWUbRh4wvgMhX2f7EtoDSqX1y_OwF9RgjLvc.cache +2 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/woubQ3T_RRQDsMosM6-mmlJMMsxmT-w16njeEdHzjG4.cache +1 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/zLqPuG6vCF0XaKppCo40WXOlrM9beqArYTWlSUS9lp4.cache +1 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/v3.0/zNDIuWl4KLiHQ06qzTYjxaWnLh0wa5ePZnqir-PW_KQ.cache +1 -0
  89. data/test/dummy/tmp/pids/server.pid +1 -0
  90. data/test/robot_catcher_test.rb +7 -0
  91. data/test/test_helper.rb +19 -0
  92. metadata +260 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Mike Voets
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,34 @@
1
+ begin
2
+ require 'bundler/setup'
3
+ rescue LoadError
4
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
+ end
6
+
7
+ require 'rdoc/task'
8
+
9
+ RDoc::Task.new(:rdoc) do |rdoc|
10
+ rdoc.rdoc_dir = 'rdoc'
11
+ rdoc.title = 'RobotCatcher'
12
+ rdoc.options << '--line-numbers'
13
+ rdoc.rdoc_files.include('README.rdoc')
14
+ rdoc.rdoc_files.include('lib/**/*.rb')
15
+ end
16
+
17
+
18
+
19
+
20
+
21
+
22
+ Bundler::GemHelper.install_tasks
23
+
24
+ require 'rake/testtask'
25
+
26
+ Rake::TestTask.new(:test) do |t|
27
+ t.libs << 'lib'
28
+ t.libs << 'test'
29
+ t.pattern = 'test/**/*_test.rb'
30
+ t.verbose = false
31
+ end
32
+
33
+
34
+ task default: :test
@@ -0,0 +1,164 @@
1
+ module RobotCatcher
2
+ module Helpers
3
+ class FormBuilder < ActionView::Helpers::FormBuilder
4
+ def initialize(object_name, object, template, options)
5
+ @spinner = options[:spinner]
6
+ if object_name.nil? and object.nil?
7
+ @nested_child_index = {}
8
+ @template, @options = template, options
9
+ @default_options = @options ? @options.slice(:index, :namespace) : {}
10
+ @multipart = nil
11
+ @index = options[:index] || options[:child_index]
12
+ else
13
+ super(object_name, object, template, options)
14
+ end
15
+ end
16
+
17
+ def self.create_tagged_field(method_name)
18
+ define_method(method_name) do |label, *args|
19
+ if method_name.eql? :label
20
+ super(label, *args)
21
+ else
22
+ hash_tag = Digest::MD5.hexdigest(label.to_s + @spinner + "robotcatcher")
23
+ @template.text_field_tag(hash_tag, nil, :style=>"display:none") +
24
+ super(label, *args)
25
+ end
26
+ end
27
+ end
28
+
29
+ field_helpers.each do |name|
30
+ create_tagged_field(name)
31
+ end
32
+ end
33
+
34
+ module FormTagHelper
35
+ extend ActiveSupport::Concern
36
+
37
+ included do
38
+ class_attribute :field_tag_helpers
39
+ self.field_tag_helpers = [:rc_text_field_tag, :rc_password_field_tag, :rc_range_field_tag,
40
+ :rc_hidden_field_tag, :rc_file_field_tag, :rc_text_area_tag,
41
+ :rc_check_box_tag, :rc_radio_button_tag, :rc_color_field_tag,
42
+ :rc_search_field_tag, :rc_telephone_field_tag, :rc_phone_field_tag,
43
+ :rc_date_field_tag, :rc_time_field_tag, :rc_datetime_field_tag,
44
+ :rc_datetime_local_field_tag, :rc_month_field_tag, :rc_week_field_tag,
45
+ :rc_url_field_tag, :rc_email_field_tag, :rc_number_field_tag]
46
+
47
+ def self.create_tagged_field_tag(method_name, parent_method)
48
+ define_method(method_name) do |label, *args|
49
+ hash_tag = Digest::MD5.hexdigest(label.to_s + @spinner + "robotcatcher")
50
+ text_field_tag(hash_tag, nil, :style=>"display:none") +
51
+ self.send(parent_method, label, *args)
52
+ end
53
+ end
54
+
55
+ field_tag_helpers.each do |name|
56
+ create_tagged_field_tag(name, name.to_s.sub(/rc_/, '').to_sym)
57
+ end
58
+
59
+ # (field_tag_helpers - [:check_box_tag, :radio_button_tag, :hidden_field_tag, :file_field_tag]).each do |selector|
60
+ # class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
61
+ # def #{selector}(method, options = {}) # def text_field_tag(method, options = {})
62
+ # self.send( # self.send(
63
+ # #{selector.inspect}, # "text_field_tag",
64
+ # method) # method)
65
+ # end # end
66
+ # RUBY_EVAL
67
+ # end
68
+ end
69
+
70
+ def rc_form_tag(url_for_options = {}, options = {}, &block)
71
+ if !options.has_key? :ip
72
+ raise ArgumentError, "should include ip address"
73
+ end
74
+ ip = options.delete(:ip)
75
+
76
+ timestamp = Time.now.to_i.to_s
77
+ # p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
78
+ @spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
79
+
80
+ options[:spinner] = @spinner
81
+
82
+ html_options = options[:html] ||= {}
83
+
84
+ html_options[:data] = options.delete(:data) if options.has_key?(:data)
85
+ html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
86
+ html_options[:method] = options.delete(:method) if options.has_key?(:method)
87
+ html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
88
+ html_options[:authenticity_token] = options.delete(:authenticity_token)
89
+
90
+ builder = RobotCatcher::Helpers::FormBuilder.new(nil, nil, self, options)
91
+ content = capture(builder, &block)
92
+ html_options[:multipart] ||= builder.multipart?
93
+
94
+ html_options = html_options_for_form(url_for_options, html_options)
95
+
96
+ if block_given?
97
+ output = form_tag_html(html_options)
98
+ output.safe_concat(hidden_field_tag(:timestamp, timestamp))
99
+ output.safe_concat(hidden_field_tag(:spinner, @spinner))
100
+ output << content
101
+ output.safe_concat("</form>")
102
+ else
103
+ output = form_tag_html(html_options)
104
+ output.safe_concat(hidden_field_tag(:timestamp, timestamp))
105
+ output.safe_concat(hidden_field_tag(:spinner, @spinner))
106
+ end
107
+ end
108
+ end
109
+
110
+ module FormHelper
111
+ def rc_form_for(record, *args, &block)
112
+ options = args.extract_options!
113
+ if !options.has_key? :ip
114
+ raise ArgumentError, "should include ip address"
115
+ end
116
+ ip = options.delete(:ip)
117
+
118
+ options[:builder] = RobotCatcher::Helpers::FormBuilder
119
+
120
+ timestamp = Time.now.to_i.to_s
121
+ # p "To be spinned (front-end): #{timestamp}#{ip}robotcatcher"
122
+ spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
123
+
124
+ options[:spinner] = spinner
125
+
126
+ raise ArgumentError, "Missing block" unless block_given?
127
+ html_options = options[:html] ||= {}
128
+
129
+ case record
130
+ when String, Symbol
131
+ object_name = record
132
+ object = nil
133
+ else
134
+ object = record.is_a?(Array) ? record.last : record
135
+ raise ArgumentError, "First argument in form cannot contain nil or be empty" unless object
136
+ object_name = options[:as] || model_name_from_record_or_class(object).param_key
137
+ apply_form_for_options!(record, object, options)
138
+ end
139
+
140
+ html_options[:data] = options.delete(:data) if options.has_key?(:data)
141
+ html_options[:remote] = options.delete(:remote) if options.has_key?(:remote)
142
+ html_options[:method] = options.delete(:method) if options.has_key?(:method)
143
+ html_options[:enforce_utf8] = options.delete(:enforce_utf8) if options.has_key?(:enforce_utf8)
144
+ html_options[:authenticity_token] = options.delete(:authenticity_token)
145
+
146
+ builder = instantiate_builder(object_name, object, options)
147
+ content = capture(builder, &block)
148
+ html_options[:multipart] ||= builder.multipart?
149
+
150
+ html_options = html_options_for_form(options[:url] || {}, html_options)
151
+
152
+ output = form_tag_html(html_options)
153
+ output.safe_concat(hidden_field_tag(:timestamp, timestamp))
154
+ output.safe_concat(hidden_field_tag(:spinner, spinner))
155
+ output << content
156
+ output.safe_concat("</form>")
157
+ end
158
+ end
159
+
160
+ end
161
+ end
162
+
163
+ ActionView::Helpers::FormTagHelper.send :include, RobotCatcher::Helpers::FormTagHelper
164
+ ActionView::Helpers::FormHelper.send :include, RobotCatcher::Helpers::FormHelper
@@ -0,0 +1,55 @@
1
+ module RobotCatcher
2
+ module Models
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ def robot_catch(*params)
7
+ @@rc_params = params
8
+
9
+ self.class_eval do
10
+ def robot?(params, ip)
11
+ timestamp = params["timestamp"]
12
+
13
+ if timestamp.nil? or \
14
+ timestamp.to_i < Time.now.to_i - 300 or timestamp.to_i > Time.now.to_i
15
+ # p "Timestamp: #{timestamp} should be between #{Time.now.to_i - 300} and #{Time.now.to_i}!"
16
+ return true
17
+ end
18
+
19
+ spinner = params["spinner"]
20
+ # p "To be spinned (back-end): #{timestamp}#{ip}robotcatcher"
21
+ hash_spinner = Digest::MD5.hexdigest(timestamp + ip.to_s + "robotcatcher")
22
+
23
+ if spinner.nil? or spinner != hash_spinner
24
+ # p "Spinner: #{spinner}" is not equal #{hash_spinner}!"
25
+ return true
26
+ end
27
+
28
+ object_name = self.class.name.downcase
29
+ object_params = params.include?(object_name) && \
30
+ params[object_name].is_a?(Hash) ? params[object_name] : params
31
+
32
+ to_be_validated = object_params.select {|k,v| @@rc_params.include? k.to_sym}
33
+
34
+ if to_be_validated.length != @@rc_params.length
35
+ # p "Keys to be validated: did not find all keys!"
36
+ return true
37
+ end
38
+
39
+ to_be_validated.each do |k, v|
40
+ hash = Digest::MD5.hexdigest(k.to_s + hash_spinner + "robotcatcher")
41
+ if !params.include? hash or !params[hash].empty?
42
+ # p "Key hash: #{k}'s hash was wrong!
43
+ return true
44
+ end
45
+ end
46
+
47
+ false
48
+ end
49
+ end
50
+ end
51
+ end
52
+ end
53
+ end
54
+
55
+ ActiveRecord::Base.send :include, RobotCatcher::Models
@@ -0,0 +1,3 @@
1
+ module RobotCatcher
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,5 @@
1
+ require 'robot_catcher/models.rb'
2
+ require 'robot_catcher/helpers.rb'
3
+
4
+ module RobotCatcher
5
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :robot_catcher do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,28 @@
1
+ == README
2
+
3
+ This README would normally document whatever steps are necessary to get the
4
+ application up and running.
5
+
6
+ Things you may want to cover:
7
+
8
+ * Ruby version
9
+
10
+ * System dependencies
11
+
12
+ * Configuration
13
+
14
+ * Database creation
15
+
16
+ * Database initialization
17
+
18
+ * How to run the test suite
19
+
20
+ * Services (job queues, cache servers, search engines, etc.)
21
+
22
+ * Deployment instructions
23
+
24
+ * ...
25
+
26
+
27
+ Please feel free to use a different markup language if you do not plan to run
28
+ <tt>rake doc:app</tt>.
@@ -0,0 +1,6 @@
1
+ # Add your own tasks in files placed in lib/tasks ending in .rake,
2
+ # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake.
3
+
4
+ require File.expand_path('../config/application', __FILE__)
5
+
6
+ Rails.application.load_tasks
@@ -0,0 +1,13 @@
1
+ // This is a manifest file that'll be compiled into application.js, which will include all the files
2
+ // listed below.
3
+ //
4
+ // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts,
5
+ // or any plugin's vendor/assets/javascripts directory can be referenced here using a relative path.
6
+ //
7
+ // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the
8
+ // compiled file.
9
+ //
10
+ // Read Sprockets README (https://github.com/rails/sprockets#sprockets-directives) for details
11
+ // about supported directives.
12
+ //
13
+ //= require_tree .
@@ -0,0 +1,2 @@
1
+ // Place all the behaviors and hooks related to the matching controller here.
2
+ // All this logic will automatically be available in application.js.
@@ -0,0 +1,15 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or any plugin's vendor/assets/stylesheets directory can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the bottom of the
9
+ * compiled file so the styles you add here take precedence over styles defined in any styles
10
+ * defined in the other CSS/SCSS files in this directory. It is generally better to create a new
11
+ * file per style scope.
12
+ *
13
+ *= require_tree .
14
+ *= require_self
15
+ */
@@ -0,0 +1,4 @@
1
+ /*
2
+ Place all the styles related to the matching controller here.
3
+ They will automatically be included in application.css.
4
+ */
@@ -0,0 +1,56 @@
1
+ body { background-color: #fff; color: #333; }
2
+
3
+ body, p, ol, ul, td {
4
+ font-family: verdana, arial, helvetica, sans-serif;
5
+ font-size: 13px;
6
+ line-height: 18px;
7
+ }
8
+
9
+ pre {
10
+ background-color: #eee;
11
+ padding: 10px;
12
+ font-size: 11px;
13
+ }
14
+
15
+ a { color: #000; }
16
+ a:visited { color: #666; }
17
+ a:hover { color: #fff; background-color:#000; }
18
+
19
+ div.field, div.actions {
20
+ margin-bottom: 10px;
21
+ }
22
+
23
+ #notice {
24
+ color: green;
25
+ }
26
+
27
+ .field_with_errors {
28
+ padding: 2px;
29
+ background-color: red;
30
+ display: table;
31
+ }
32
+
33
+ #error_explanation {
34
+ width: 450px;
35
+ border: 2px solid red;
36
+ padding: 7px;
37
+ padding-bottom: 0;
38
+ margin-bottom: 20px;
39
+ background-color: #f0f0f0;
40
+ }
41
+
42
+ #error_explanation h2 {
43
+ text-align: left;
44
+ font-weight: bold;
45
+ padding: 5px 5px 5px 15px;
46
+ font-size: 12px;
47
+ margin: -7px;
48
+ margin-bottom: 0px;
49
+ background-color: #c00;
50
+ color: #fff;
51
+ }
52
+
53
+ #error_explanation ul li {
54
+ font-size: 12px;
55
+ list-style: square;
56
+ }
@@ -0,0 +1,5 @@
1
+ class ApplicationController < ActionController::Base
2
+ # Prevent CSRF attacks by raising an exception.
3
+ # For APIs, you may want to use :null_session instead.
4
+ protect_from_forgery with: :exception
5
+ end
@@ -0,0 +1,68 @@
1
+ class ArticlesController < ApplicationController
2
+ before_action :set_article, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /articles
5
+ def index
6
+ @articles = Article.all
7
+ end
8
+
9
+ # GET /articles/1
10
+ def show
11
+ end
12
+
13
+ # GET /articles/new
14
+ def new
15
+ @article = Article.new
16
+ end
17
+
18
+ # GET /articles/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /articles
23
+ def create
24
+ @article = Article.new(article_params)
25
+
26
+ if @article.robot?(params, request.remote_ip)
27
+ redirect_to @article, notice: 'Stupid robot.'
28
+ return
29
+ end
30
+
31
+ if @article.save
32
+ redirect_to @article, notice: 'Article was successfully created.'
33
+ else
34
+ render :new
35
+ end
36
+ end
37
+
38
+ # PATCH/PUT /articles/1
39
+ def update
40
+ if @article.robot?(params, request.remote_ip)
41
+ redirect_to @article, notice: 'Stupid robot.'
42
+ return
43
+ end
44
+
45
+ if @article.update(arcticle_params)
46
+ redirect_to @article, notice: 'Article was successfully updated.'
47
+ else
48
+ render :edit
49
+ end
50
+ end
51
+
52
+ # DELETE /articles/1
53
+ def destroy
54
+ @article.destroy
55
+ redirect_to articles_url, notice: 'Article was successfully destroyed.'
56
+ end
57
+
58
+ private
59
+ # Use callbacks to share common setup or constraints between actions.
60
+ def set_article
61
+ @article = Article.find(params[:id])
62
+ end
63
+
64
+ # Only allow a trusted parameter "white list" through.
65
+ def article_params
66
+ params.require(:article).permit(:title, :text)
67
+ end
68
+ end