scaffold_assoc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.rdoc +3 -0
- data/Rakefile +32 -0
- data/lib/generators/scaffold_assoc/install/install_generator.rb +21 -0
- data/lib/generators/scaffold_assoc/scaffold_assoc_generator.rb +158 -0
- data/lib/generators/scaffold_assoc/templates/controller.rb +75 -0
- data/lib/generators/scaffold_assoc/templates/erb/_form.html.erb +37 -0
- data/lib/generators/scaffold_assoc/templates/erb/edit.html.erb +6 -0
- data/lib/generators/scaffold_assoc/templates/erb/index.html.erb +29 -0
- data/lib/generators/scaffold_assoc/templates/erb/new.html.erb +5 -0
- data/lib/generators/scaffold_assoc/templates/erb/show.html.erb +11 -0
- data/lib/generators/scaffold_assoc/templates/haml/_form.html.haml +15 -0
- data/lib/generators/scaffold_assoc/templates/haml/edit.html.haml +7 -0
- data/lib/generators/scaffold_assoc/templates/haml/index.html.haml +23 -0
- data/lib/generators/scaffold_assoc/templates/haml/new.html.haml +4 -0
- data/lib/generators/scaffold_assoc/templates/haml/show.html.haml +11 -0
- data/lib/generators/scaffold_assoc/templates/migration.rb +15 -0
- data/lib/generators/scaffold_assoc/templates/model.rb +3 -0
- data/lib/scaffold_assoc/version.rb +3 -0
- data/lib/scaffold_assoc.rb +2 -0
- data/lib/tasks/scaffold_assoc_tasks.rake +4 -0
- data/test/dummy/README.rdoc +28 -0
- data/test/dummy/Rakefile +6 -0
- data/test/dummy/app/assets/javascripts/application.js +13 -0
- data/test/dummy/app/assets/javascripts/posts.js +2 -0
- data/test/dummy/app/assets/stylesheets/application.css +13 -0
- data/test/dummy/app/assets/stylesheets/posts.css +4 -0
- data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
- data/test/dummy/app/controllers/application_controller.rb +5 -0
- data/test/dummy/app/controllers/comments_controller.rb +65 -0
- data/test/dummy/app/controllers/posts_controller.rb +58 -0
- data/test/dummy/app/helpers/application_helper.rb +2 -0
- data/test/dummy/app/helpers/posts_helper.rb +2 -0
- data/test/dummy/app/models/comment.rb +3 -0
- data/test/dummy/app/models/post.rb +2 -0
- data/test/dummy/app/views/comments/_form.html.erb +25 -0
- data/test/dummy/app/views/comments/edit.html.erb +6 -0
- data/test/dummy/app/views/comments/index.html.erb +27 -0
- data/test/dummy/app/views/comments/new.html.erb +5 -0
- data/test/dummy/app/views/comments/show.html.erb +14 -0
- data/test/dummy/app/views/layouts/application.html.erb +14 -0
- data/test/dummy/app/views/posts/_form.html.erb +25 -0
- data/test/dummy/app/views/posts/edit.html.erb +6 -0
- data/test/dummy/app/views/posts/index.html.erb +29 -0
- data/test/dummy/app/views/posts/new.html.erb +5 -0
- data/test/dummy/app/views/posts/show.html.erb +15 -0
- data/test/dummy/bin/bundle +3 -0
- data/test/dummy/bin/rails +4 -0
- data/test/dummy/bin/rake +4 -0
- data/test/dummy/config/application.rb +23 -0
- data/test/dummy/config/boot.rb +5 -0
- data/test/dummy/config/database.yml +25 -0
- data/test/dummy/config/environment.rb +5 -0
- data/test/dummy/config/environments/development.rb +29 -0
- data/test/dummy/config/environments/production.rb +80 -0
- data/test/dummy/config/environments/test.rb +36 -0
- data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/test/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/test/dummy/config/initializers/inflections.rb +16 -0
- data/test/dummy/config/initializers/mime_types.rb +5 -0
- data/test/dummy/config/initializers/secret_token.rb +12 -0
- data/test/dummy/config/initializers/session_store.rb +3 -0
- data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/test/dummy/config/locales/en.yml +23 -0
- data/test/dummy/config/routes.rb +63 -0
- data/test/dummy/config.ru +4 -0
- data/test/dummy/db/development.sqlite3 +0 -0
- data/test/dummy/db/migrate/20150408174454_create_posts.rb +10 -0
- data/test/dummy/db/migrate/20150408174500_create_comments.rb +17 -0
- data/test/dummy/db/schema.rb +31 -0
- data/test/dummy/log/development.log +693 -0
- data/test/dummy/public/404.html +58 -0
- data/test/dummy/public/422.html +58 -0
- data/test/dummy/public/500.html +57 -0
- data/test/dummy/public/favicon.ico +0 -0
- data/test/dummy/test/controllers/posts_controller_test.rb +49 -0
- data/test/dummy/test/fixtures/posts.yml +9 -0
- data/test/dummy/test/models/post_test.rb +7 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/13fe41fee1fe35b49d145bcc06610705 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/1e8f75a6b5b33970fb8e397347caa0a1 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/24204f742af588c8166d3160b500d20f +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/2f5173deea6c795b8fdde723bb4b63af +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/357970feca3ac29060c1e3861e2c0953 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/371bf96e99717688ed7313a0c53f4212 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/416150dc3ac35079c94273cc46e90aa6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/510da110ae528e2d22533be39ff696c5 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/5384ad85f52d3272dbc64d46ef3876a4 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/6fc757c2c8329244ca95d6909865bbc2 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/c85016e7bbd4f3adbb7635d01f85d39b +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/cffd775d018f68ce5dba1ee0d951a994 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d066c004d1fd26ae76a61303a7a18145 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/d771ace226fc8215a3572e0aa35bb0d6 +0 -0
- data/test/dummy/tmp/cache/assets/development/sprockets/f7cbd26ba1d28d48de824f0e94586655 +0 -0
- data/test/scaffold_assoc_test.rb +7 -0
- data/test/test_helper.rb +15 -0
- 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,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,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>.
|
data/test/dummy/Rakefile
ADDED
@@ -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,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,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,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,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,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,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) %>
|