scaffold_assoc 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (97) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +3 -0
  4. data/Rakefile +32 -0
  5. data/lib/generators/scaffold_assoc/install/install_generator.rb +21 -0
  6. data/lib/generators/scaffold_assoc/scaffold_assoc_generator.rb +158 -0
  7. data/lib/generators/scaffold_assoc/templates/controller.rb +75 -0
  8. data/lib/generators/scaffold_assoc/templates/erb/_form.html.erb +37 -0
  9. data/lib/generators/scaffold_assoc/templates/erb/edit.html.erb +6 -0
  10. data/lib/generators/scaffold_assoc/templates/erb/index.html.erb +29 -0
  11. data/lib/generators/scaffold_assoc/templates/erb/new.html.erb +5 -0
  12. data/lib/generators/scaffold_assoc/templates/erb/show.html.erb +11 -0
  13. data/lib/generators/scaffold_assoc/templates/haml/_form.html.haml +15 -0
  14. data/lib/generators/scaffold_assoc/templates/haml/edit.html.haml +7 -0
  15. data/lib/generators/scaffold_assoc/templates/haml/index.html.haml +23 -0
  16. data/lib/generators/scaffold_assoc/templates/haml/new.html.haml +4 -0
  17. data/lib/generators/scaffold_assoc/templates/haml/show.html.haml +11 -0
  18. data/lib/generators/scaffold_assoc/templates/migration.rb +15 -0
  19. data/lib/generators/scaffold_assoc/templates/model.rb +3 -0
  20. data/lib/scaffold_assoc/version.rb +3 -0
  21. data/lib/scaffold_assoc.rb +2 -0
  22. data/lib/tasks/scaffold_assoc_tasks.rake +4 -0
  23. data/test/dummy/README.rdoc +28 -0
  24. data/test/dummy/Rakefile +6 -0
  25. data/test/dummy/app/assets/javascripts/application.js +13 -0
  26. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  27. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  28. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  29. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  30. data/test/dummy/app/controllers/application_controller.rb +5 -0
  31. data/test/dummy/app/controllers/comments_controller.rb +65 -0
  32. data/test/dummy/app/controllers/posts_controller.rb +58 -0
  33. data/test/dummy/app/helpers/application_helper.rb +2 -0
  34. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  35. data/test/dummy/app/models/comment.rb +3 -0
  36. data/test/dummy/app/models/post.rb +2 -0
  37. data/test/dummy/app/views/comments/_form.html.erb +25 -0
  38. data/test/dummy/app/views/comments/edit.html.erb +6 -0
  39. data/test/dummy/app/views/comments/index.html.erb +27 -0
  40. data/test/dummy/app/views/comments/new.html.erb +5 -0
  41. data/test/dummy/app/views/comments/show.html.erb +14 -0
  42. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  43. data/test/dummy/app/views/posts/_form.html.erb +25 -0
  44. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  45. data/test/dummy/app/views/posts/index.html.erb +29 -0
  46. data/test/dummy/app/views/posts/new.html.erb +5 -0
  47. data/test/dummy/app/views/posts/show.html.erb +15 -0
  48. data/test/dummy/bin/bundle +3 -0
  49. data/test/dummy/bin/rails +4 -0
  50. data/test/dummy/bin/rake +4 -0
  51. data/test/dummy/config/application.rb +23 -0
  52. data/test/dummy/config/boot.rb +5 -0
  53. data/test/dummy/config/database.yml +25 -0
  54. data/test/dummy/config/environment.rb +5 -0
  55. data/test/dummy/config/environments/development.rb +29 -0
  56. data/test/dummy/config/environments/production.rb +80 -0
  57. data/test/dummy/config/environments/test.rb +36 -0
  58. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  59. data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  60. data/test/dummy/config/initializers/inflections.rb +16 -0
  61. data/test/dummy/config/initializers/mime_types.rb +5 -0
  62. data/test/dummy/config/initializers/secret_token.rb +12 -0
  63. data/test/dummy/config/initializers/session_store.rb +3 -0
  64. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  65. data/test/dummy/config/locales/en.yml +23 -0
  66. data/test/dummy/config/routes.rb +63 -0
  67. data/test/dummy/config.ru +4 -0
  68. data/test/dummy/db/development.sqlite3 +0 -0
  69. data/test/dummy/db/migrate/20150408174454_create_posts.rb +10 -0
  70. data/test/dummy/db/migrate/20150408174500_create_comments.rb +17 -0
  71. data/test/dummy/db/schema.rb +31 -0
  72. data/test/dummy/log/development.log +693 -0
  73. data/test/dummy/public/404.html +58 -0
  74. data/test/dummy/public/422.html +58 -0
  75. data/test/dummy/public/500.html +57 -0
  76. data/test/dummy/public/favicon.ico +0 -0
  77. data/test/dummy/test/controllers/posts_controller_test.rb +49 -0
  78. data/test/dummy/test/fixtures/posts.yml +9 -0
  79. data/test/dummy/test/models/post_test.rb +7 -0
  80. data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
  81. data/test/dummy/tmp/cache/assets/development/sprockets/1e8f75a6b5b33970fb8e397347caa0a1 +0 -0
  82. data/test/dummy/tmp/cache/assets/development/sprockets/24204f742af588c8166d3160b500d20f +0 -0
  83. data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
  84. data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
  85. data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
  86. data/test/dummy/tmp/cache/assets/development/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
  87. data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
  88. data/test/dummy/tmp/cache/assets/development/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
  89. data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
  90. data/test/dummy/tmp/cache/assets/development/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
  91. data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
  92. data/test/dummy/tmp/cache/assets/development/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
  93. data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
  94. data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
  95. data/test/scaffold_assoc_test.rb +7 -0
  96. data/test/test_helper.rb +15 -0
  97. metadata +240 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: da281a0faf589cde7cdd9a09b8b9c013b142820c
4
+ data.tar.gz: 68815d596c324af225bd9f82f29b8f6a539d3026
5
+ SHA512:
6
+ metadata.gz: dbb7baaa736de4e1d1703309eac7ca938b990d2ede482bb2eaddd668719a36c8902daeeb35eff1be86e2c5eef0ab06f3791399be7ff7939a3fab8c5cdfc1fbcc
7
+ data.tar.gz: ff8f8e1454bb75b7b049ef22c80ef48d2da198001e28f9161fd64fed69b54795aba769f2000b624e391bda1c9d25c5cb4151ed058a3d0498c2b8d94328e7698a
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2014 YOURNAME
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/README.rdoc ADDED
@@ -0,0 +1,3 @@
1
+ = ScaffoldAssoc
2
+
3
+ This project rocks and uses MIT-LICENSE.
data/Rakefile ADDED
@@ -0,0 +1,32 @@
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 = 'ScaffoldAssoc'
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
+ Bundler::GemHelper.install_tasks
21
+
22
+ require 'rake/testtask'
23
+
24
+ Rake::TestTask.new(:test) do |t|
25
+ t.libs << 'lib'
26
+ t.libs << 'test'
27
+ t.pattern = 'test/**/*_test.rb'
28
+ t.verbose = false
29
+ end
30
+
31
+
32
+ task default: :test
@@ -0,0 +1,21 @@
1
+ module ScaffoldAssoc
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+
5
+ desc <<DESC
6
+ Description:
7
+ Copy scaffold_assoc view templates to your application.
8
+ DESC
9
+
10
+ def self.source_root
11
+ @source_root ||= File.expand_path(File.join(File.dirname(__FILE__), '../templates'))
12
+ end
13
+
14
+ def install
15
+ directory 'erb', 'lib/rails/scaffold_assoc/templates/erb'
16
+ directory 'haml', 'lib/rails/scaffold_assoc/templates/haml'
17
+ end
18
+
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,158 @@
1
+ module Rails
2
+ module Generators
3
+ class ScaffoldAssocGenerator < NamedBase # :nodoc:
4
+
5
+ include Rails::Generators::Migration
6
+
7
+ attr_accessor :parent_name, :flags
8
+
9
+ def source_paths
10
+ [
11
+ File.expand_path(File.join(File.dirname(__FILE__), '../../rails/scaffold_assoc/templates')),
12
+ File.expand_path(File.join(File.dirname(__FILE__), '/templates'))]
13
+ end
14
+
15
+ argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]"
16
+
17
+ class_option :orm, :banner => "NAME", :type => :string, :required => true, :default => :active_record,
18
+ :desc => "ORM to generate the controller for"
19
+
20
+ class_option :template_engine, :default => :erb
21
+ class_option :force_plural, type: :boolean, desc: "Forces the use of a plural ModelName"
22
+ class_option :skip_model, :type => :boolean, :default => false, :desc => "Don't generate a model or migration."
23
+ class_option :skip_migration, :type => :boolean, :default => false, :desc => "Don't generate migration for model."
24
+ class_option :skip_controller, :type => :boolean, :default => false, :desc => "Don't generate controller for model."
25
+ class_option :skip_views, :type => :boolean, :default => false, :desc => "Don't generate views for model."
26
+
27
+ hook_for :form_builder, :as => :scaffold
28
+
29
+ def initialize(args, *options)
30
+ a = args[0].split("/")
31
+ self.parent_name = a[0]
32
+ name = a[1]
33
+ args[0] = name
34
+ super
35
+ assign_controller_names!(name.pluralize)
36
+ end
37
+
38
+ def scaffold_assoc_create_migration
39
+ if options[:skip_model] || options[:skip_migration]
40
+ return
41
+ end
42
+ migration_template 'migration.rb', File.join('db/migrate/', "create_" + plural_table_name + ".rb")
43
+ end
44
+
45
+ def self.next_migration_number(path)
46
+ @migration_number = current_migration_number(path) + 1
47
+ ActiveRecord::Migration.next_migration_number(@migration_number)
48
+ end
49
+
50
+ def create_route
51
+ gsub_file "config/routes.rb", /(\s*resources :#{parent_table_name})\s*\n/, <<-CODE
52
+ \\1 do
53
+ end
54
+ CODE
55
+ insert_into_file "config/routes.rb", after: /(\s*resources :#{parent_table_name})\s*do\s*\n/ do
56
+ <<-CODE
57
+ resources :#{table_name}
58
+ CODE
59
+ end
60
+ end
61
+
62
+ def create_model
63
+ if options[:skip_model]
64
+ return
65
+ end
66
+ template 'model.rb', File.join('app/models', singular_table_name + ".rb")
67
+ end
68
+
69
+ def create_controller_files
70
+ if options[:skip_controller]
71
+ return
72
+ end
73
+ template "controller.rb", File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
74
+ end
75
+
76
+ def copy_view_files
77
+ if options[:skip_views]
78
+ return
79
+ end
80
+ available_views.each do |view|
81
+ filename = [view, 'html', handler].compact.join(".")
82
+ template "#{handler}/#{view}.html.#{handler}", File.join("app/views", controller_file_path, filename)
83
+ end
84
+ end
85
+
86
+ protected
87
+
88
+ attr_reader :controller_name, :controller_file_name
89
+
90
+ def available_views
91
+ %w(index edit show new _form)
92
+ end
93
+
94
+ def handler
95
+ options[:template_engine]
96
+ end
97
+
98
+ def parent_table_name
99
+ return parent_name.tableize
100
+ end
101
+
102
+ def parent_singular_table_name
103
+ return parent_table_name.singularize
104
+ end
105
+
106
+ def controller_class_path
107
+ if options[:model_name]
108
+ @controller_class_path
109
+ else
110
+ class_path
111
+ end
112
+ end
113
+
114
+ def assign_controller_names!(name)
115
+ @controller_name = name
116
+ @controller_class_path = name.include?('/') ? name.split('/') : name.split('::')
117
+ @controller_class_path.map! { |m| m.underscore }
118
+ @controller_file_name = @controller_class_path.pop
119
+ end
120
+
121
+ def controller_file_path
122
+ @controller_file_path ||= (controller_class_path + [controller_file_name]).join('/')
123
+ end
124
+
125
+ def controller_class_name
126
+ (controller_class_path + [controller_file_name]).map!{ |m| m.camelize }.join('::')
127
+ end
128
+
129
+ def controller_i18n_scope
130
+ @controller_i18n_scope ||= controller_file_path.tr('/', '.')
131
+ end
132
+
133
+ # Loads the ORM::Generators::ActiveModel class. This class is responsible
134
+ # to tell scaffold entities how to generate an specific method for the
135
+ # ORM. Check Rails::Generators::ActiveModel for more information.
136
+ def orm_class
137
+ @orm_class ||= begin
138
+ # Raise an error if the class_option :orm was not defined.
139
+ unless self.class.class_options[:orm]
140
+ raise "You need to have :orm as class option to invoke orm_class and orm_instance"
141
+ end
142
+
143
+ begin
144
+ "#{options[:orm].to_s.camelize}::Generators::ActiveModel".constantize
145
+ rescue NameError
146
+ Rails::Generators::ActiveModel
147
+ end
148
+ end
149
+ end
150
+
151
+ # Initialize ORM::Generators::ActiveModel to access instance methods.
152
+ def orm_instance(name=singular_table_name)
153
+ @orm_instance ||= orm_class.new(name)
154
+ end
155
+
156
+ end
157
+ end
158
+ end
@@ -0,0 +1,75 @@
1
+ <% if namespaced? -%>
2
+ require_dependency "<%= namespaced_file_path %>/application_controller"
3
+
4
+ <% end -%>
5
+ <% module_namespacing do -%>
6
+ class <%= controller_class_name %>Controller < ApplicationController
7
+ before_action :set_<%= parent_singular_table_name %>, only: [:new, :create, :index, :show, :edit, :update, :destroy]
8
+ before_action :set_<%= singular_table_name %>, only: [:show, :edit, :update, :destroy]
9
+
10
+ # GET <%= route_url %>
11
+ def index
12
+ @<%= plural_table_name %> = @<%= parent_singular_table_name %> ? <%= class_name %>.where(<%= parent_singular_table_name %>: @<%= parent_singular_table_name %>) : <%= orm_class.all(class_name) %>
13
+ end
14
+
15
+ # GET <%= route_url %>/1
16
+ def show
17
+ end
18
+
19
+ # GET <%= route_url %>/new
20
+ def new
21
+ @<%= singular_table_name %> = <%= orm_class.build(class_name) %>
22
+ @<%= singular_table_name %>.<%= parent_singular_table_name %> = @<%= parent_singular_table_name %>
23
+ end
24
+
25
+ # GET <%= route_url %>/1/edit
26
+ def edit
27
+ end
28
+
29
+ # POST <%= route_url %>
30
+ def create
31
+ @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %>
32
+ @<%= singular_table_name %>.<%= parent_singular_table_name %> = @<%= parent_singular_table_name %>
33
+ if @<%= orm_instance.save %>
34
+ redirect_to <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, @<%= singular_table_name %>), notice: <%= "'#{human_name} was successfully created.'" %>
35
+ else
36
+ render action: 'new'
37
+ end
38
+ end
39
+
40
+ # PATCH/PUT <%= route_url %>/1
41
+ def update
42
+ if @<%= orm_instance.update("#{singular_table_name}_params") %>
43
+ redirect_to <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, @<%= singular_table_name %>), notice: <%= "'#{human_name} was successfully updated.'" %>
44
+ else
45
+ render action: 'edit'
46
+ end
47
+ end
48
+
49
+ # DELETE <%= route_url %>/1
50
+ def destroy
51
+ @<%= orm_instance.destroy %>
52
+ redirect_to <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>), notice: <%= "'#{human_name} was successfully destroyed.'" %>
53
+ end
54
+
55
+ private
56
+ # Use callbacks to share common setup or constraints between actions.
57
+ def set_<%= singular_table_name %>
58
+ @<%= singular_table_name %> = <%= orm_class.find(class_name, "params[:id]") %>
59
+ end
60
+
61
+ # Use callbacks to share common setup or constraints between actions.
62
+ def set_<%= parent_name.tableize.singularize %>
63
+ @<%= parent_name.tableize.singularize %> = <%= orm_class.find(parent_name, "params[:" + parent_name.tableize.singularize + "_id]") %>
64
+ end
65
+
66
+ # Only allow a trusted parameter "white list" through.
67
+ def <%= "#{singular_table_name}_params" %>
68
+ <%- if attributes_names.empty? -%>
69
+ params[:<%= singular_table_name %>]
70
+ <%- else -%>
71
+ params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
72
+ <%- end -%>
73
+ end
74
+ end
75
+ <% end -%>
@@ -0,0 +1,37 @@
1
+ <%%= form_for([@<%= parent_singular_table_name %>, @<%= singular_table_name %>]) do |f| %>
2
+ <%% if @<%= singular_table_name %>.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%%= pluralize(@<%= singular_table_name %>.errors.count, "error") %> prohibited this <%= singular_table_name %> from being saved:</h2>
5
+
6
+ <ul>
7
+ <%% @<%= singular_table_name %>.errors.full_messages.each do |msg| %>
8
+ <li><%%= msg %></li>
9
+ <%% end %>
10
+ </ul>
11
+ </div>
12
+ <%% end %>
13
+
14
+ <% attributes.each do |attribute| -%>
15
+ <div class="field">
16
+ <% if attribute.password_digest? -%>
17
+ <%%= f.label :password %><br>
18
+ <%%= f.password_field :password %>
19
+ </div>
20
+ <div>
21
+ <%%= f.label :password_confirmation %><br>
22
+ <%%= f.password_field :password_confirmation %>
23
+ <% else -%>
24
+ <%- if attribute.reference? -%>
25
+ <%%= f.label :<%= attribute.column_name %> %><br>
26
+ <%%= f.<%= attribute.field_type %> :<%= attribute.column_name %> %>
27
+ <%- else -%>
28
+ <%%= f.label :<%= attribute.name %> %><br>
29
+ <%%= f.<%= attribute.field_type %> :<%= attribute.name %> %>
30
+ <%- end -%>
31
+ <% end -%>
32
+ </div>
33
+ <% end -%>
34
+ <div class="actions">
35
+ <%%= f.submit %>
36
+ </div>
37
+ <%% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Show', <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, @<%= singular_table_name %>) %> |
6
+ <%%= link_to 'Back', <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>) %>
@@ -0,0 +1,29 @@
1
+ <h1>Listing <%= plural_table_name %></h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
7
+ <th><%= attribute.human_name %></th>
8
+ <% end -%>
9
+ <th colspan="3"></th>
10
+ </tr>
11
+ </thead>
12
+
13
+ <tbody>
14
+ <%% @<%= plural_table_name %>.each do |<%= singular_table_name %>| %>
15
+ <tr>
16
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
17
+ <td><%%= <%= singular_table_name %>.<%= attribute.name %> %></td>
18
+ <% end -%>
19
+ <td><%%= link_to 'Show', <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, <%= singular_table_name %>) %></td>
20
+ <td><%%= link_to 'Edit', edit_<%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, <%= singular_table_name %>) %></td>
21
+ <td><%%= link_to 'Destroy', <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, <%= singular_table_name %>), method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <%% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%%= link_to 'New <%= human_name %>', new_<%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>) %>
@@ -0,0 +1,5 @@
1
+ <h1>New <%= singular_table_name %></h1>
2
+
3
+ <%%= render 'form' %>
4
+
5
+ <%%= link_to 'Back', <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>) %>
@@ -0,0 +1,11 @@
1
+ <p id="notice"><%%= notice %></p>
2
+
3
+ <% attributes.reject(&:password_digest?).each do |attribute| -%>
4
+ <p>
5
+ <strong><%= attribute.human_name %>:</strong>
6
+ <%%= @<%= singular_table_name %>.<%= attribute.name %> %>
7
+ </p>
8
+
9
+ <% end -%>
10
+ <%%= link_to 'Edit', edit_<%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, @<%= singular_table_name %>) %> |
11
+ <%%= link_to 'Back', <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>) %>
@@ -0,0 +1,15 @@
1
+ = form_for [@<%= parent_singular_table_name %>, @<%= singular_table_name %>] do |f|
2
+ - if @<%= singular_table_name %>.errors.any?
3
+ #error_explanation
4
+ %h2= "#{pluralize(@<%= singular_table_name %>.errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
5
+ %ul
6
+ - @<%= singular_table_name %>.errors.full_messages.each do |msg|
7
+ %li= msg
8
+
9
+ <% for attribute in attributes -%>
10
+ .field
11
+ = f.label :<%= attribute.name %>
12
+ = f.<%= attribute.field_type %> :<%= attribute.name %>
13
+ <% end -%>
14
+ .actions
15
+ = f.submit 'Save'
@@ -0,0 +1,7 @@
1
+ %h1
2
+ Editing <%= singular_table_name %>
3
+ = render 'form'
4
+
5
+ = link_to 'Show', <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, @<%= singular_table_name %>)
6
+ = " | "
7
+ = link_to 'Back', <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>)