rails_app_generator 0.1.12 → 0.1.15

Sign up to get free protection for your applications and to get access to all the features.
Files changed (57) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +1 -0
  3. data/CHANGELOG.md +22 -0
  4. data/after_templates/addons/acts_as_list/_.rb +62 -0
  5. data/after_templates/addons/acts_as_list/app/controllers/home_controller.rb +7 -0
  6. data/after_templates/addons/acts_as_list/app/controllers/todo_items_controller.rb +132 -0
  7. data/after_templates/addons/acts_as_list/app/models/todo_item.rb +23 -0
  8. data/after_templates/addons/acts_as_list/app/models/todo_list.rb +12 -0
  9. data/after_templates/addons/acts_as_list/app/views/home/index.html.erb +23 -0
  10. data/after_templates/addons/acts_as_list/app/views/layouts/_alerts.html.erb +2 -0
  11. data/after_templates/addons/acts_as_list/app/views/layouts/_footer.html.erb +3 -0
  12. data/after_templates/addons/acts_as_list/app/views/layouts/_navbar.html.erb +8 -0
  13. data/after_templates/addons/acts_as_list/app/views/layouts/application.html.erb +28 -0
  14. data/after_templates/addons/acts_as_list/app/views/todo_items/_todo_item.html.erb +21 -0
  15. data/after_templates/addons/acts_as_list/app/views/todo_items/index.html.erb +25 -0
  16. data/after_templates/addons/acts_as_list/config/routes.rb +15 -0
  17. data/after_templates/addons/acts_as_list/db/seeds.rb +17 -0
  18. data/after_templates/addons/honeybadger/_.rb +46 -0
  19. data/after_templates/addons/honeybadger/app/controllers/application_controller.rb +9 -0
  20. data/after_templates/addons/honeybadger/app/controllers/errors_controller.rb +17 -0
  21. data/after_templates/addons/honeybadger/app/controllers/products_controller.rb +72 -0
  22. data/after_templates/addons/honeybadger/app/views/home/index.html.erb +49 -0
  23. data/after_templates/addons/honeybadger/public/404.html +69 -0
  24. data/after_templates/addons/honeybadger/public/500.html +68 -0
  25. data/after_templates/addons/twilio_ruby/_.rb +23 -0
  26. data/after_templates/addons/twilio_ruby/app/controllers/home_controller.rb +54 -0
  27. data/after_templates/addons/twilio_ruby/app/views/home/index.html.erb +27 -0
  28. data/after_templates/addons/twilio_ruby/config/initializers/twilio.rb +4 -0
  29. data/lib/rails_app_generator/add_on.rb +36 -0
  30. data/lib/rails_app_generator/addons/acts_as_list.rb +26 -0
  31. data/lib/rails_app_generator/addons/honeybadger.rb +19 -0
  32. data/lib/rails_app_generator/app_generator.rb +134 -116
  33. data/lib/rails_app_generator/options/rails_options.rb +3 -0
  34. data/lib/rails_app_generator/version.rb +1 -1
  35. data/package-lock.json +2 -2
  36. data/package.json +1 -1
  37. data/profiles/addons/acts_as_list.json +13 -0
  38. data/profiles/addons/{rails_html_sanitizer.json → honeybadger.json} +3 -3
  39. data/profiles/addons/twilio_ruby.json +12 -0
  40. data/tasks/addon.thor +45 -8
  41. data/tasks/profile.thor +40 -23
  42. data/templates/addons/honeybadger/en.yml +10 -0
  43. data/templates/addons/honeybadger/honeybadger.sample.yml +37 -0
  44. data/templates/thor_task/addon/addon.tt +13 -6
  45. data/templates/thor_task/profile/after_template.rb +54 -0
  46. data/templates/thor_task/profile/app/controllers/home_controller.rb +7 -0
  47. data/templates/thor_task/profile/app/views/home/index.html.erb.tt +23 -0
  48. data/templates/thor_task/profile/app/views/layouts/_alerts.html.erb.tt +2 -0
  49. data/templates/thor_task/profile/app/views/layouts/_footer.html.erb.tt +3 -0
  50. data/templates/thor_task/profile/app/views/layouts/_navbar.html.erb +7 -0
  51. data/templates/thor_task/profile/app/views/layouts/application.html.erb.tt +28 -0
  52. data/templates/thor_task/profile/config/initializers/addon_name.rb +1 -0
  53. data/templates/thor_task/profile/db/seeds.rb +16 -0
  54. metadata +43 -6
  55. data/after_templates/addons/rails_html_sanitizer_xxx/home/index.html.erb +0 -31
  56. data/templates/thor_task/profile/after_template.rb.tt +0 -15
  57. data/templates/thor_task/profile/home/index.html.erb.tt +0 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f2307c0ebef36cdf172922b01efbf07d2e24adaa855afca17b7e6490dd4b3e45
4
- data.tar.gz: 6dff48114607c3adaa8ef5325651762e0738a62032e9e50e6f41e1c7cfbae536
3
+ metadata.gz: 1a70b5c05cd9a463bcfde6eeaf50a48380c37dc39a88e3c8239e145fee4b1934
4
+ data.tar.gz: 5c1bbda9632a77534a36943bc81594b14a38ab2654c3de3f61a19e8cb5b8d9d6
5
5
  SHA512:
6
- metadata.gz: e1daf6f4579973228d26d984c4db2adf8531091fd9bb169a17ead6df4c641e817f3fe29ba3bf929b5f674a11323ecce929eb2e839d79a866ed82f7725cdfd3b4
7
- data.tar.gz: ea7d93cb6434418ab160fc2d37b6981b9a6056b26fa8f49baa198d3084be07e06e29d09ef2af0d6893b34d68bc2d2521f9d07e02a3439faa1e0b78a4d048ac2d
6
+ metadata.gz: 43579cfcb2ca45ffeb1d7f8f504b7c480ab7e484f163c9af3e238fd5a066d26942e860167f7e2c91a1aa69b98ced19000538eacacee38a18b8382a6ea4201c7e
7
+ data.tar.gz: a099c2c9e2cb390101fccd6363a2957cbc58e049994f16ecde69a7545572b5e8fa472fa64dca63026c16da4601305f2e4615968ea507c4e1151f889625eb9b27
data/.rubocop.yml CHANGED
@@ -12,6 +12,7 @@ AllCops:
12
12
  - "spec/samples/**/*"
13
13
  - "a/**/*"
14
14
  - "after_templates/**/*"
15
+ - "templates/**/*"
15
16
 
16
17
  Metrics/BlockLength:
17
18
  Exclude:
data/CHANGELOG.md CHANGED
@@ -1,3 +1,25 @@
1
+ ## [0.1.14](https://github.com/klueless-io/rails_app_generator/compare/v0.1.13...v0.1.14) (2022-08-04)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * add twilio addon ([2a70a12](https://github.com/klueless-io/rails_app_generator/commit/2a70a1216dc9d7475289a154f6c7b8c4a2a80403))
7
+
8
+ ## [0.1.13](https://github.com/klueless-io/rails_app_generator/compare/v0.1.12...v0.1.13) (2022-08-03)
9
+
10
+
11
+ ### Bug Fixes
12
+
13
+ * add honeybadger addon ([5118957](https://github.com/klueless-io/rails_app_generator/commit/511895750056a8eff7bc41c0cc902ff81cfcd7d3))
14
+ * add honeybadger addon + cops ([e105b47](https://github.com/klueless-io/rails_app_generator/commit/e105b47790c2a91a0a9ec0224f8a7aecb75067a9))
15
+
16
+ ## [0.1.12](https://github.com/klueless-io/rails_app_generator/compare/v0.1.11...v0.1.12) (2022-08-02)
17
+
18
+
19
+ ### Bug Fixes
20
+
21
+ * update rails-html-sanitizer example ([7f3a2d8](https://github.com/klueless-io/rails_app_generator/commit/7f3a2d810a968748baf4f8a4a147b086a26781c0))
22
+
1
23
  ## [0.1.11](https://github.com/klueless-io/rails_app_generator/compare/v0.1.10...v0.1.11) (2022-08-02)
2
24
 
3
25
 
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require 'pry'
4
+
5
+ # This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.
6
+ #
7
+ # exe/rag addons/acts_as_list
8
+
9
+ self.local_template_path = File.dirname(__FILE__)
10
+
11
+ gac 'base rails 7 image created'
12
+
13
+ add_controller('home', 'index')
14
+ route("root 'home#index'")
15
+
16
+ force_copy
17
+
18
+ add_scaffold('todo_list', 'name')
19
+ add_scaffold('todo_item', 'task', 'position:integer', 'todo_list:references')
20
+
21
+ copy_file 'app/controllers/home_controller.rb' , 'app/controllers/home_controller.rb'
22
+ copy_file 'app/controllers/todo_items_controller.rb' , 'app/controllers/todo_items_controller.rb'
23
+ copy_file 'app/models/todo_list.rb' , 'app/models/todo_list.rb'
24
+ copy_file 'app/models/todo_item.rb' , 'app/models/todo_item.rb'
25
+
26
+ copy_file 'app/views/home/index.html.erb' , 'app/views/home/index.html.erb'
27
+
28
+ copy_file 'app/views/layouts/_alerts.html.erb' , 'app/views/layouts/_alerts.html.erb'
29
+ copy_file 'app/views/layouts/_navbar.html.erb' , 'app/views/layouts/_navbar.html.erb'
30
+ copy_file 'app/views/layouts/_footer.html.erb' , 'app/views/layouts/_footer.html.erb'
31
+ template 'app/views/layouts/application.html.erb' , 'app/views/layouts/application.html.erb'
32
+
33
+ copy_file 'app/views/todo_items/index.html.erb' , 'app/views/todo_items/index.html.erb'
34
+ copy_file 'app/views/todo_items/_todo_item.html.erb' , 'app/views/todo_items/_todo_item.html.erb'
35
+
36
+ copy_file 'config/routes.rb' , 'config/routes.rb'
37
+
38
+ template 'db/seeds.rb' , 'db/seeds.rb'
39
+
40
+ after_bundle do
41
+ setup_db
42
+ end
43
+
44
+ def setup_db
45
+
46
+ db_migrate
47
+ rails_command('db:seed')
48
+ end
49
+
50
+ # Other template command examples
51
+ # css_install('tailwind')
52
+ # rails_command('db:migrate')
53
+ # bundle_add('hotwire-rails')
54
+ # rails_command('hotwire:install')
55
+ # run('bin/importmap pin sortablejs')
56
+ # run('npm install daisyui')
57
+ # create_file 'app/assets/stylesheets/custom-bootstrap-import.scss' , read_template('custom-bootstrap-import.scss')
58
+ # append_to_file 'app/assets/config/manifest.js' , read_template('manifest.js')
59
+ # insert_into_file 'app/views/layouts/application.html.erb', read_template('application.html.erb'),
60
+ # before: %( <%= javascript_include_tag "application", "data-turbo-track": "reload", defer: true %>)
61
+ # gsub_file 'app/views/layouts/application.html.erb', %(container mx-auto mt-28 px-5 flex), 'container mx-auto px-5'
62
+ # template 'home.css', 'app/assets/stylesheets/home.css'
@@ -0,0 +1,7 @@
1
+ class HomeController < ApplicationController
2
+ def index
3
+ end
4
+
5
+ def some_action
6
+ end
7
+ end
@@ -0,0 +1,132 @@
1
+ class TodoItemsController < ApplicationController
2
+ before_action :set_todo_item, only: %i[
3
+ show
4
+ edit
5
+ update
6
+ destroy
7
+ insert_at
8
+ move_lower
9
+ move_higher
10
+ move_to_bottom
11
+ move_to_top
12
+ remove_from_list
13
+ ]
14
+
15
+ before_action :set_todo_items, only: %i[
16
+ index
17
+ insert_at
18
+ move_lower
19
+ move_higher
20
+ move_to_bottom
21
+ move_to_top
22
+ remove_from_list
23
+ ]
24
+
25
+ # GET /todo_items or /todo_items.json
26
+ def index
27
+ end
28
+
29
+ # GET /todo_items/1 or /todo_items/1.json
30
+ def show
31
+ end
32
+
33
+ def insert_at
34
+ @todo_item.insert_at(2)
35
+ render :index, params
36
+ end
37
+
38
+ def move_lower
39
+ @todo_item.move_lower
40
+ render :index, params
41
+ end
42
+
43
+ def move_higher
44
+ @todo_item.move_higher
45
+ render :index, params
46
+ end
47
+
48
+ def move_to_bottom
49
+ @todo_item.move_to_bottom
50
+ render :index, params
51
+ end
52
+
53
+ def move_to_top
54
+ @todo_item.move_to_top
55
+ render :index, params
56
+ end
57
+
58
+ def remove_from_list
59
+ @todo_item.remove_from_list
60
+ render :index, params
61
+ end
62
+
63
+ # GET /todo_items/new
64
+ def new
65
+ @todo_item = TodoItem.new
66
+ end
67
+
68
+ # GET /todo_items/1/edit
69
+ def edit
70
+ end
71
+
72
+ # POST /todo_items or /todo_items.json
73
+ def create
74
+ @todo_item = TodoItem.new(todo_item_params)
75
+
76
+ respond_to do |format|
77
+ if @todo_item.save
78
+ format.html { redirect_to todo_item_url(@todo_item), notice: "Todo item was successfully created." }
79
+ format.json { render :show, status: :created, location: @todo_item }
80
+ else
81
+ format.html { render :new, status: :unprocessable_entity }
82
+ format.json { render json: @todo_item.errors, status: :unprocessable_entity }
83
+ end
84
+ end
85
+ end
86
+
87
+ # PATCH/PUT /todo_items/1 or /todo_items/1.json
88
+ def update
89
+ respond_to do |format|
90
+ if @todo_item.update(todo_item_params)
91
+ format.html { redirect_to todo_item_url(@todo_item), notice: "Todo item was successfully updated." }
92
+ format.json { render :show, status: :ok, location: @todo_item }
93
+ else
94
+ format.html { render :edit, status: :unprocessable_entity }
95
+ format.json { render json: @todo_item.errors, status: :unprocessable_entity }
96
+ end
97
+ end
98
+ end
99
+
100
+ # DELETE /todo_items/1 or /todo_items/1.json
101
+ def destroy
102
+ @todo_item.destroy
103
+
104
+ respond_to do |format|
105
+ format.html { redirect_to todo_items_url, notice: "Todo item was successfully destroyed." }
106
+ format.json { head :no_content }
107
+ end
108
+ end
109
+
110
+ def query_params
111
+ params.permit(:todo_list_id)
112
+ end
113
+ helper_method :query_params
114
+
115
+ private
116
+ # Use callbacks to share common setup or constraints between actions.
117
+ def set_todo_item
118
+ @todo_item = TodoItem.find(params[:id])
119
+ end
120
+
121
+ def set_todo_items
122
+ todo_list_id = params[:todo_list_id]
123
+
124
+ @todo_items = todo_list_id.nil? ? TodoItem.all : TodoItem.where(todo_list_id: todo_list_id)
125
+ @todo_items = @todo_items.order(:todo_list_id, :position)
126
+ end
127
+
128
+ # Only allow a list of trusted parameters through.
129
+ def todo_item_params
130
+ params.require(:todo_item).permit(:task, :position, :todo_list_id)
131
+ end
132
+ end
@@ -0,0 +1,23 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: todo_items
4
+ #
5
+ # id :integer not null, primary key
6
+ # position :integer
7
+ # task :string
8
+ # created_at :datetime not null
9
+ # updated_at :datetime not null
10
+ # todo_list_id :integer not null
11
+ #
12
+ # Indexes
13
+ #
14
+ # index_todo_items_on_todo_list_id (todo_list_id)
15
+ #
16
+ # Foreign Keys
17
+ #
18
+ # todo_list_id (todo_list_id => todo_lists.id)
19
+ #
20
+ class TodoItem < ApplicationRecord
21
+ belongs_to :todo_list
22
+ acts_as_list scope: :todo_list
23
+ end
@@ -0,0 +1,12 @@
1
+ # == Schema Information
2
+ #
3
+ # Table name: todo_lists
4
+ #
5
+ # id :integer not null, primary key
6
+ # name :string
7
+ # created_at :datetime not null
8
+ # updated_at :datetime not null
9
+ #
10
+ class TodoList < ApplicationRecord
11
+ has_many :todo_items, -> { order(position: :asc) }
12
+ end
@@ -0,0 +1,23 @@
1
+ <style>
2
+ .alert { color: red; }
3
+ .notice { color: green; }
4
+ </style>
5
+
6
+ <% flash.each do |type, msg| %><div class="<%= type %>"><%= msg %></div><% end %>
7
+ <% if flash.any? %><hr /><% end %>
8
+
9
+ <h1>Acts as list</h1>
10
+
11
+ <h2>This "acts_as" extension provides the capabilities for sorting and reordering a number of objects in a list. The class that has this specified needs to have a "position" column defined as an integer on the mapped database table.</h2>
12
+
13
+ <!--
14
+ Add/Remove as needed
15
+ -->
16
+
17
+ <!--
18
+ <= link_to 'Some Action', home_some_action_path %>
19
+
20
+ <= link_to 'Products', products_path %> |
21
+ <= link_to 'Posts', posts_path %> |
22
+ <= link_to 'People', people_path %>
23
+ -->
@@ -0,0 +1,2 @@
1
+ <% flash.each do |type, msg| %><div class="<%= type %>"><%= msg %></div><% end %>
2
+ <% if flash.any? %><hr /><% end %>
@@ -0,0 +1,3 @@
1
+ <footer>
2
+ <hr />
3
+ </footer>
@@ -0,0 +1,8 @@
1
+ <header>
2
+ <%= link_to 'Home', root_path %> |
3
+ <%= link_to 'ToDo List', todo_lists_path %> |
4
+ <%= link_to 'ToDo Items', todo_items_path %> |
5
+ <%= link_to 'People', todo_items_path(todo_list_id: TodoList.find_by(name: 'people')) %> |
6
+ <%= link_to 'Jobs', todo_items_path(todo_list_id: TodoList.find_by(name: 'jobs')) %>
7
+ <hr />
8
+ </header>
@@ -0,0 +1,28 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= camelized %></title>
5
+ <meta name="viewport" content="width=device-width,initial-scale=1">
6
+ <%%= csrf_meta_tags %>
7
+ <%%= csp_meta_tag %>
8
+
9
+ <%- if options[:skip_hotwire] || options[:skip_javascript] -%>
10
+ <%%= stylesheet_link_tag "application" %>
11
+ <%- else -%>
12
+ <%%= stylesheet_link_tag "application", "data-turbo-track": "reload" %>
13
+ <%- end -%>
14
+ <style>
15
+ .alert { color: red; }
16
+ .notice { color: green; }
17
+ </style>
18
+ </head>
19
+
20
+ <body>
21
+ <%%= render 'layouts/navbar' %>
22
+ <main>
23
+ <%%= render 'layouts/alerts' %>
24
+ <%%= yield %>
25
+ </main>
26
+ <%%= render 'layouts/footer' %>
27
+ </body>
28
+ </html>
@@ -0,0 +1,21 @@
1
+ <tr>
2
+ <td>
3
+ <%= todo_item.task %>
4
+ </td>
5
+ <td>
6
+ <%= todo_item.position %>
7
+ </td>
8
+ <td>
9
+ <%= todo_item.todo_list.name %>
10
+ </td>
11
+ <td>
12
+ <%= link_to "Show", todo_item %> |
13
+ <%= link_to "Insert At #2", insert_at_todo_item_path(todo_item.id, **query_params) %> |
14
+ <%= link_to "Higher", move_higher_todo_item_path(todo_item.id, **query_params) %> |
15
+ <%= link_to "Lower", move_lower_todo_item_path(todo_item.id, **query_params) %> |
16
+ <%= link_to "Top", move_to_top_todo_item_path(todo_item.id, **query_params) %> |
17
+ <%= link_to "Bottom", move_to_bottom_todo_item_path(todo_item.id, **query_params) %> |
18
+ <%= link_to "Remove From List", remove_from_list_todo_item_path(todo_item.id, **query_params) %>
19
+ </td>
20
+ </tr>
21
+
@@ -0,0 +1,25 @@
1
+ <p style="color: green"><%= notice %></p>
2
+
3
+ <h1>Todo items</h1>
4
+
5
+ <div id="todo_items">
6
+ <table>
7
+ <thead>
8
+ <tr>
9
+ <th>Task</th>
10
+ <th>Position</th>
11
+ <th>List Name</th>
12
+ </tr>
13
+ </thead>
14
+ <tbody>
15
+
16
+ <% @todo_items.each do |todo_item| %>
17
+ <%= render todo_item %>
18
+ <% end %>
19
+
20
+ </tbody>
21
+ </table>
22
+
23
+ </div>
24
+
25
+ <%= link_to "New todo item", new_todo_item_path %>
@@ -0,0 +1,15 @@
1
+ Rails.application.routes.draw do
2
+ resources :todo_items do
3
+ member do
4
+ get :insert_at
5
+ get :move_lower
6
+ get :move_higher
7
+ get :move_to_bottom
8
+ get :move_to_top
9
+ get :remove_from_list
10
+ end
11
+ end
12
+ resources :todo_lists
13
+ root 'home#index'
14
+ get 'home/index'
15
+ end
@@ -0,0 +1,17 @@
1
+ # This file should contain all the record creation needed to seed the database with its default values.
2
+ # The data can then be loaded with the bin/rails db:seed command (or created alongside the database with db:setup).
3
+ #
4
+ # User.find_or_create_by(email: "admin@admin.com") do |user|
5
+ # user.name = 'Admin'
6
+ # user.password = 'password'
7
+ # user.admin = true
8
+ # end
9
+
10
+ people = TodoList.create(name: 'people')
11
+ jobs = TodoList.create(name: 'jobs')
12
+ # lisa = User.create(email: 'lisa@site.com', name: 'lisa', password: 'password')
13
+
14
+ 5.times do |i|
15
+ TodoItem.create(todo_list: people, task: "Person Name #{i}", position: i)
16
+ TodoItem.create(todo_list: jobs , task: "Profession #{i}", position: i)
17
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ # require 'pry'
4
+
5
+ # Make managing application errors a more pleasant experience.
6
+ #
7
+ # exe/rag addons/honeybadger
8
+ # see: https://honeybadger.wistia.com/medias/l3cmyucx8f
9
+
10
+ self.local_template_path = File.dirname(__FILE__)
11
+
12
+ gac 'base rails 7 image created'
13
+
14
+ add_controller('home', 'index')
15
+ route("root 'home#index'")
16
+
17
+ force_copy
18
+
19
+ copy_file 'app/views/home/index.html.erb', 'app/views/home/index.html.erb'
20
+ copy_file 'app/controllers/application_controller.rb', 'app/controllers/application_controller.rb'
21
+ copy_file 'app/controllers/errors_controller.rb', 'app/controllers/errors_controller.rb'
22
+
23
+ # Test if this is really needed
24
+ insert_into_file 'config/application.rb', after: 'class Application < Rails::Application' do
25
+ <<-RUBY
26
+ config.generators.system_tests = nil
27
+ RUBY
28
+ end
29
+
30
+ copy_file 'public/404.html', 'public/404.html'
31
+ copy_file 'public/500.html', 'public/500.html'
32
+
33
+ copy_file 'config/locales/en.yml', 'config/locales/en.yml'
34
+
35
+ move_file('config/honeybadger.sample.yml', 'config/honeybadger.yml')
36
+
37
+ after_bundle do
38
+ setup_db
39
+ end
40
+
41
+ def setup_db
42
+ add_scaffold('product', 'name', 'price:integer')
43
+ copy_file 'app/controllers/products_controller.rb', 'app/controllers/products_controller.rb'
44
+
45
+ db_migrate
46
+ end
@@ -0,0 +1,9 @@
1
+ class ApplicationController < ActionController::Base
2
+ before_action do |_|
3
+ Honeybadger.context(
4
+ user_email: 'klueless-io@example.com',
5
+ name: 'David',
6
+ company: 'AppyDave'
7
+ )
8
+ end
9
+ end
@@ -0,0 +1,17 @@
1
+ class ErrorsController < ApplicationController
2
+ def not_found
3
+ render status: 404
4
+ end
5
+
6
+ def internal_server
7
+ render status: 500
8
+ end
9
+
10
+ def unprocessable
11
+ render status: 422
12
+ end
13
+
14
+ def unacceptable
15
+ render status: 406
16
+ end
17
+ end
@@ -0,0 +1,72 @@
1
+ class ProductsController < ApplicationController
2
+ before_action :set_product, only: %i[ show edit update destroy ]
3
+
4
+ # GET /products or /products.json
5
+ def index
6
+ @products = Product.all
7
+ end
8
+
9
+ # GET /products/1 or /products/1.json
10
+ def show
11
+ end
12
+
13
+ # GET /products/new
14
+ def new
15
+ # remove this comment to see error in Honeybadger
16
+ raise 'Oh No!'
17
+ @product = Product.new
18
+ end
19
+
20
+ # GET /products/1/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /products or /products.json
25
+ def create
26
+ @product = Product.new(product_params)
27
+
28
+ respond_to do |format|
29
+ if @product.save
30
+ format.html { redirect_to product_url(@product), notice: "Product was successfully created." }
31
+ format.json { render :show, status: :created, location: @product }
32
+ else
33
+ format.html { render :new, status: :unprocessable_entity }
34
+ format.json { render json: @product.errors, status: :unprocessable_entity }
35
+ end
36
+ end
37
+ end
38
+
39
+ # PATCH/PUT /products/1 or /products/1.json
40
+ def update
41
+ respond_to do |format|
42
+ if @product.update(product_params)
43
+ format.html { redirect_to product_url(@product), notice: "Product was successfully updated." }
44
+ format.json { render :show, status: :ok, location: @product }
45
+ else
46
+ format.html { render :edit, status: :unprocessable_entity }
47
+ format.json { render json: @product.errors, status: :unprocessable_entity }
48
+ end
49
+ end
50
+ end
51
+
52
+ # DELETE /products/1 or /products/1.json
53
+ def destroy
54
+ @product.destroy
55
+
56
+ respond_to do |format|
57
+ format.html { redirect_to products_url, notice: "Product was successfully destroyed." }
58
+ format.json { head :no_content }
59
+ end
60
+ end
61
+
62
+ private
63
+ # Use callbacks to share common setup or constraints between actions.
64
+ def set_product
65
+ @product = Product.find(params[:id])
66
+ end
67
+
68
+ # Only allow a list of trusted parameters through.
69
+ def product_params
70
+ params.require(:product).permit(:name, :price)
71
+ end
72
+ end
@@ -0,0 +1,49 @@
1
+ <h1>Honeybadger</h1>
2
+
3
+ <h2>Make managing application errors a more pleasant experience.</h2>
4
+
5
+ <p>Follow the instructions below and then click on products -> new</p>
6
+
7
+ <%= link_to 'Products', products_path %>
8
+
9
+ <h2>Instructions</h2>
10
+
11
+ <p>If you want to see 404/500 HTML inplace of the debug routing error when in development then alter the following file</p>
12
+
13
+ <b>config/environments/development.rb</b>
14
+ <pre>
15
+
16
+ # config.consider_all_requests_local = true
17
+ config.consider_all_requests_local = false
18
+
19
+ </pre>
20
+
21
+ <p>If you want to see the exception message in Honeybadger then make sure then remove the comment<p>
22
+
23
+ <b>config/honeybadger.yml</b>
24
+
25
+ <pre>
26
+ # report_data: true
27
+ report_data: true
28
+ </pre>
29
+
30
+ <p>If you want to send the exception message to Honeybadger then make sure your remove development from the list<p>
31
+
32
+ <pre>
33
+ # development_environments:
34
+ - test
35
+ - development
36
+ - cucumber
37
+ </pre>
38
+
39
+ <p>Test frrom the command line using</p>
40
+
41
+ <pre>
42
+ bundle exec honeybadger test
43
+ </pre>
44
+
45
+ <p>More information can be found at
46
+ <a href="http://honeybadger.io/">http://honeybadger.io/</a> and
47
+ <a hreg="https://honeybadger.wistia.com/medias/l3cmyucx8f">https://honeybadger.wistia.com/medias/l3cmyucx8f</a>
48
+
49
+ </p>