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
@@ -0,0 +1,23 @@
1
+ %h1
2
+ Listing <%= plural_table_name %>
3
+ %table
4
+ %thead
5
+ %tr
6
+ <% attributes.each_with_index do |attribute, index| -%>
7
+ %th <%= attribute.human_name %>
8
+ <% end -%>
9
+ %th{:colspan => "3"}
10
+ %tbody
11
+ - @<%= plural_table_name %>.each do |<%= singular_table_name %>|
12
+ %tr
13
+ <% for attribute in attributes -%>
14
+ %td= <%= singular_table_name %>.<%= attribute.name %>
15
+ <% end -%>
16
+ %td
17
+ = link_to 'Show', <%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, <%= singular_table_name %>)
18
+ %td
19
+ = link_to 'Edit', edit_<%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, <%= singular_table_name %>)
20
+ %td
21
+ = 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?' }
22
+ %br
23
+ = link_to 'New <%= human_name %>', new_<%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>)
@@ -0,0 +1,4 @@
1
+ %h1 New <%= singular_table_name %>
2
+ = render 'form'
3
+
4
+ = link_to 'Back', <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>)
@@ -0,0 +1,11 @@
1
+ %p#notice
2
+ = notice
3
+ <% for attribute in attributes -%>
4
+ %p
5
+ %strong
6
+ <%= attribute.human_name %>:
7
+ = @<%= singular_table_name %>.<%= attribute.name %>
8
+ <% end -%>
9
+ = link_to 'Edit', edit_<%= parent_singular_table_name %>_<%= singular_table_name %>_path(@<%= parent_singular_table_name %>, @<%= singular_table_name %>)
10
+ = " | "
11
+ = link_to 'Back', <%= parent_singular_table_name %>_<%= plural_table_name %>_path(@<%= parent_singular_table_name %>)
@@ -0,0 +1,15 @@
1
+ class Create<%= table_name.classify.pluralize %> < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :<%= table_name %> do |t|
4
+ <% attributes.each do |a| %>
5
+ t.<%= a.type %> :<%= a.name %>
6
+ <% end %>
7
+ t.integer :<%= parent_singular_table_name %>_id
8
+ t.timestamps
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ drop_table :<%= table_name %>
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ class <%= class_name %> < ActiveRecord::Base
2
+ belongs_to :<%= parent_singular_table_name %>
3
+ end
@@ -0,0 +1,3 @@
1
+ module ScaffoldAssoc
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,2 @@
1
+ module ScaffoldAssoc
2
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :scaffold_assoc 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
+ Dummy::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 vendor/assets/javascripts of plugins, if any, 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/sstephenson/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,13 @@
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 vendor/assets/stylesheets of plugins, if any, 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 top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ *= require_tree .
13
+ */
@@ -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,65 @@
1
+ class CommentsController < ApplicationController
2
+ before_action :set_post, only: [:new, :create, :index, :show, :edit, :update, :destroy]
3
+ before_action :set_comment, only: [:show, :edit, :update, :destroy]
4
+
5
+ # GET /comments
6
+ def index
7
+ @comments = @post ? Comment.where(post: @post) : Comment.all
8
+ end
9
+
10
+ # GET /comments/1
11
+ def show
12
+ end
13
+
14
+ # GET /comments/new
15
+ def new
16
+ @comment = Comment.new
17
+ @comment.post = @post
18
+ end
19
+
20
+ # GET /comments/1/edit
21
+ def edit
22
+ end
23
+
24
+ # POST /comments
25
+ def create
26
+ @comment = Comment.new(comment_params)
27
+ @comment.post = @post
28
+ if @comment.save
29
+ redirect_to post_comment_path(@post, @comment), notice: 'Comment was successfully created.'
30
+ else
31
+ render action: 'new'
32
+ end
33
+ end
34
+
35
+ # PATCH/PUT /comments/1
36
+ def update
37
+ if @comment.update(comment_params)
38
+ redirect_to post_comment_path(@post, @comment), notice: 'Comment was successfully updated.'
39
+ else
40
+ render action: 'edit'
41
+ end
42
+ end
43
+
44
+ # DELETE /comments/1
45
+ def destroy
46
+ @comment.destroy
47
+ redirect_to post_comments_path(@post), notice: 'Comment was successfully destroyed.'
48
+ end
49
+
50
+ private
51
+ # Use callbacks to share common setup or constraints between actions.
52
+ def set_comment
53
+ @comment = Comment.find(params[:id])
54
+ end
55
+
56
+ # Use callbacks to share common setup or constraints between actions.
57
+ def set_post
58
+ @post = Post.find(params[:post_id])
59
+ end
60
+
61
+ # Only allow a trusted parameter "white list" through.
62
+ def comment_params
63
+ params.require(:comment).permit(:title, :content)
64
+ end
65
+ end
@@ -0,0 +1,58 @@
1
+ class PostsController < ApplicationController
2
+ before_action :set_post, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /posts
5
+ def index
6
+ @posts = Post.all
7
+ end
8
+
9
+ # GET /posts/1
10
+ def show
11
+ end
12
+
13
+ # GET /posts/new
14
+ def new
15
+ @post = Post.new
16
+ end
17
+
18
+ # GET /posts/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /posts
23
+ def create
24
+ @post = Post.new(post_params)
25
+
26
+ if @post.save
27
+ redirect_to @post, notice: 'Post was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /posts/1
34
+ def update
35
+ if @post.update(post_params)
36
+ redirect_to @post, notice: 'Post was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /posts/1
43
+ def destroy
44
+ @post.destroy
45
+ redirect_to posts_url, notice: 'Post was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_post
51
+ @post = Post.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def post_params
56
+ params.require(:post).permit(:title, :content)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,3 @@
1
+ class Comment < ActiveRecord::Base
2
+ belongs_to :post
3
+ end
@@ -0,0 +1,2 @@
1
+ class Post < ActiveRecord::Base
2
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for([@post, @comment]) do |f| %>
2
+ <% if @comment.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@comment.errors.count, "error") %> prohibited this comment from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @comment.errors.full_messages.each do |msg| %>
8
+ <li><%= msg %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :title %><br>
16
+ <%= f.text_field :title %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :content %><br>
20
+ <%= f.text_area :content %>
21
+ </div>
22
+ <div class="actions">
23
+ <%= f.submit %>
24
+ </div>
25
+ <% end %>
@@ -0,0 +1,6 @@
1
+ <h1>Editing comment</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Show', post_comment_path(@post, @comment) %> |
6
+ <%= link_to 'Back', post_comments_path(@post) %>
@@ -0,0 +1,27 @@
1
+ <h1>Listing comments</h1>
2
+
3
+ <table>
4
+ <thead>
5
+ <tr>
6
+ <th>Title</th>
7
+ <th>Content</th>
8
+ <th colspan="3"></th>
9
+ </tr>
10
+ </thead>
11
+
12
+ <tbody>
13
+ <% @comments.each do |comment| %>
14
+ <tr>
15
+ <td><%= comment.title %></td>
16
+ <td><%= comment.content %></td>
17
+ <td><%= link_to 'Show', post_comment_path(@post, comment) %></td>
18
+ <td><%= link_to 'Edit', edit_post_comment_path(@post, comment) %></td>
19
+ <td><%= link_to 'Destroy', post_comment_path(@post, comment), method: :delete, data: { confirm: 'Are you sure?' } %></td>
20
+ </tr>
21
+ <% end %>
22
+ </tbody>
23
+ </table>
24
+
25
+ <br>
26
+
27
+ <%= link_to 'New Comment', new_post_comment_path(@post) %>
@@ -0,0 +1,5 @@
1
+ <h1>New comment</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', post_comments_path(@post) %>
@@ -0,0 +1,14 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Title:</strong>
5
+ <%= @comment.title %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Content:</strong>
10
+ <%= @comment.content %>
11
+ </p>
12
+
13
+ <%= link_to 'Edit', edit_post_comment_path(@post, @comment) %> |
14
+ <%= link_to 'Back', post_comments_path(@post) %>