hashids_rails 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. checksums.yaml +7 -0
  2. data/MIT-LICENSE +20 -0
  3. data/README.rdoc +33 -0
  4. data/Rakefile +34 -0
  5. data/lib/hashids_rails/version.rb +3 -0
  6. data/lib/hashids_rails.rb +83 -0
  7. data/test/dummy/README.rdoc +28 -0
  8. data/test/dummy/Rakefile +6 -0
  9. data/test/dummy/app/assets/javascripts/application.js +13 -0
  10. data/test/dummy/app/assets/javascripts/comments.js +2 -0
  11. data/test/dummy/app/assets/javascripts/posts.js +2 -0
  12. data/test/dummy/app/assets/javascripts/users.js +2 -0
  13. data/test/dummy/app/assets/stylesheets/application.css +15 -0
  14. data/test/dummy/app/assets/stylesheets/comments.css +4 -0
  15. data/test/dummy/app/assets/stylesheets/posts.css +4 -0
  16. data/test/dummy/app/assets/stylesheets/scaffold.css +56 -0
  17. data/test/dummy/app/assets/stylesheets/users.css +4 -0
  18. data/test/dummy/app/controllers/application_controller.rb +5 -0
  19. data/test/dummy/app/controllers/comments_controller.rb +58 -0
  20. data/test/dummy/app/controllers/posts_controller.rb +58 -0
  21. data/test/dummy/app/controllers/users_controller.rb +58 -0
  22. data/test/dummy/app/helpers/application_helper.rb +2 -0
  23. data/test/dummy/app/helpers/comments_helper.rb +2 -0
  24. data/test/dummy/app/helpers/posts_helper.rb +2 -0
  25. data/test/dummy/app/helpers/users_helper.rb +2 -0
  26. data/test/dummy/app/models/comment.rb +2 -0
  27. data/test/dummy/app/models/post.rb +2 -0
  28. data/test/dummy/app/models/user.rb +2 -0
  29. data/test/dummy/app/views/comments/_form.html.erb +25 -0
  30. data/test/dummy/app/views/comments/edit.html.erb +6 -0
  31. data/test/dummy/app/views/comments/index.html.erb +29 -0
  32. data/test/dummy/app/views/comments/new.html.erb +5 -0
  33. data/test/dummy/app/views/comments/show.html.erb +14 -0
  34. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  35. data/test/dummy/app/views/posts/_form.html.erb +21 -0
  36. data/test/dummy/app/views/posts/edit.html.erb +6 -0
  37. data/test/dummy/app/views/posts/index.html.erb +27 -0
  38. data/test/dummy/app/views/posts/new.html.erb +5 -0
  39. data/test/dummy/app/views/posts/show.html.erb +9 -0
  40. data/test/dummy/app/views/users/_form.html.erb +21 -0
  41. data/test/dummy/app/views/users/edit.html.erb +6 -0
  42. data/test/dummy/app/views/users/index.html.erb +27 -0
  43. data/test/dummy/app/views/users/new.html.erb +5 -0
  44. data/test/dummy/app/views/users/show.html.erb +9 -0
  45. data/test/dummy/bin/bundle +3 -0
  46. data/test/dummy/bin/rails +4 -0
  47. data/test/dummy/bin/rake +4 -0
  48. data/test/dummy/bin/setup +29 -0
  49. data/test/dummy/config/application.rb +26 -0
  50. data/test/dummy/config/boot.rb +5 -0
  51. data/test/dummy/config/database.yml +25 -0
  52. data/test/dummy/config/environment.rb +5 -0
  53. data/test/dummy/config/environments/development.rb +41 -0
  54. data/test/dummy/config/environments/production.rb +79 -0
  55. data/test/dummy/config/environments/test.rb +42 -0
  56. data/test/dummy/config/initializers/assets.rb +11 -0
  57. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  58. data/test/dummy/config/initializers/cookies_serializer.rb +3 -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 +4 -0
  62. data/test/dummy/config/initializers/session_store.rb +3 -0
  63. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  64. data/test/dummy/config/locales/en.yml +23 -0
  65. data/test/dummy/config/routes.rb +59 -0
  66. data/test/dummy/config/secrets.yml +22 -0
  67. data/test/dummy/config.ru +4 -0
  68. data/test/dummy/db/development.sqlite3 +0 -0
  69. data/test/dummy/db/migrate/20150420195726_create_users.rb +9 -0
  70. data/test/dummy/db/migrate/20150420195757_create_posts.rb +9 -0
  71. data/test/dummy/db/migrate/20150420195818_create_comments.rb +10 -0
  72. data/test/dummy/db/schema.rb +35 -0
  73. data/test/dummy/db/test.sqlite3 +0 -0
  74. data/test/dummy/log/development.log +20 -0
  75. data/test/dummy/log/test.log +132 -0
  76. data/test/dummy/public/404.html +67 -0
  77. data/test/dummy/public/422.html +67 -0
  78. data/test/dummy/public/500.html +66 -0
  79. data/test/dummy/public/favicon.ico +0 -0
  80. data/test/hashids_rails_test.rb +7 -0
  81. data/test/test_helper.rb +19 -0
  82. metadata +241 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: a6f816fd46fbdcbf46b824d167babaf47344400d
4
+ data.tar.gz: 07770d6eaf85ebcc91b178865f78b783787d339b
5
+ SHA512:
6
+ metadata.gz: 42dfc9b0eabe366a2dcb1b4ed1e416db39453c7e253c4b3fa26271233ddf9c176e28f0a92664973f2ba8aa0edd5c874efdb2f367a4e924813fb1714780b47850
7
+ data.tar.gz: 57d6233252efb45e33a4459b5b94e14bc427b931ff331ec5295388c6de8a99fd90647557c9fa12c1894a27a73ad393b7f4b9cf0e8a962f0d75069226c3ae410c
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2015 Brian Petro
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,33 @@
1
+ = hashids_rails gem
2
+ Use hashids.rb(https://github.com/peterhellberg/hashids.rb) to store ActiveRecord IDs in URL non-obviously. Heavily based on obfuscate_id(https://github.com/namick/obfuscate_id).
3
+
4
+ == Installation
5
+ Add the gem to your Gemfile.
6
+
7
+ gem 'hashids_rails'
8
+
9
+ Run bundler.
10
+
11
+ bundle install
12
+
13
+ == Usage
14
+ In your model, add a single line.
15
+
16
+ class Post < ActiveRecord::Base
17
+ hash_id
18
+ end
19
+
20
+ == Customization
21
+ If you want your hash ids to be different than some other website using the same plugin, you can throw a random string (salt) at hash_id to make it hash out unique ids for your app.
22
+
23
+ class Post < ActiveRecord::Base
24
+ hash_id salt: 'bring_your_own_salt'
25
+ end
26
+
27
+ == Limitations
28
+ * This is not security. hashids_rails was created to lightly mask record id numbers for the casual user. If you need to really secure your database ids (hint, you probably don't), you need to use real encryption like AES.
29
+ * To properly generate obfuscated urls(using hash_ids), make sure you trigger the model's to_param method by passing in the whole object rather than just the id; do this: post_path(@post) not this: post_path(@post.id).
30
+
31
+ == Contributing
32
+ === TODO
33
+ * write tests
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 = 'HashidsRails'
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,3 @@
1
+ module HashidsRails
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,83 @@
1
+ module HashidsRails
2
+ # based on obfuscate_id by namick
3
+ # ref: https://github.com/namick/obfuscate_id
4
+ def hash_id(options = {})
5
+ require 'hashids'
6
+ extend ClassMethods
7
+ include InstanceMethods
8
+ cattr_accessor :hash_salt
9
+ self.hash_salt = (options[:salt] || default_salt)
10
+ end
11
+
12
+ def self.hide(id, salt)
13
+ hashids = Hashids.new(salt, 3)
14
+ hashids.encode id
15
+ end
16
+
17
+ def self.show(id, salt)
18
+ hashids = Hashids.new(salt, 3)
19
+ hashids.decode id
20
+ end
21
+
22
+ module ClassMethods
23
+ def find(*args)
24
+ scope = args.slice!(0)
25
+ options = args.slice!(0) || {}
26
+ if has_hashed_id? && !options[:no_hashed_id]
27
+ if scope.is_a?(Array)
28
+ scope.map! {|a| dehash_id(a).to_i}
29
+ else
30
+ scope = dehash_id(scope)
31
+ end
32
+ end
33
+ super(scope)
34
+ end
35
+
36
+ def has_hashed_id?
37
+ true
38
+ end
39
+
40
+ def dehash_id(hashed_id)
41
+ HashidsRails.show(hashed_id, self.hash_salt)
42
+ end
43
+
44
+ # Generate a default salt from the Model name
45
+ # This makes it easy to drop hashids onto any model
46
+ # and produce different hashes for different models
47
+ def default_salt
48
+ name
49
+ end
50
+ end
51
+
52
+ module InstanceMethods
53
+ def to_param
54
+ HashidsRails.hide(self.id, self.class.hash_salt)
55
+ end
56
+
57
+ # Override ActiveRecord::Persistence#reload
58
+ # passing in an options flag with { no_hashed_id: true }
59
+ def reload(options = nil)
60
+ options = (options || {}).merge(no_hashed_id: true)
61
+
62
+ clear_aggregation_cache
63
+ clear_association_cache
64
+
65
+ fresh_object =
66
+ if options && options[:lock]
67
+ self.class.unscoped { self.class.lock(options[:lock]).find(id, options) }
68
+ else
69
+ self.class.unscoped { self.class.find(id, options) }
70
+ end
71
+
72
+ @attributes = fresh_object.instance_variable_get('@attributes')
73
+ @new_record = false
74
+ self
75
+ end
76
+
77
+ def dehash_id(hashed_id)
78
+ self.class.dehash_id(hashed_id)
79
+ end
80
+ end
81
+ end
82
+
83
+ ActiveRecord::Base.extend HashidsRails
@@ -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,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,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,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,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,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,58 @@
1
+ class CommentsController < ApplicationController
2
+ before_action :set_comment, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /comments
5
+ def index
6
+ @comments = Comment.all
7
+ end
8
+
9
+ # GET /comments/1
10
+ def show
11
+ end
12
+
13
+ # GET /comments/new
14
+ def new
15
+ @comment = Comment.new
16
+ end
17
+
18
+ # GET /comments/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /comments
23
+ def create
24
+ @comment = Comment.new(comment_params)
25
+
26
+ if @comment.save
27
+ redirect_to @comment, notice: 'Comment was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /comments/1
34
+ def update
35
+ if @comment.update(comment_params)
36
+ redirect_to @comment, notice: 'Comment was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /comments/1
43
+ def destroy
44
+ @comment.destroy
45
+ redirect_to comments_url, notice: 'Comment was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_comment
51
+ @comment = Comment.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def comment_params
56
+ params.require(:comment).permit(:content, :post_id)
57
+ end
58
+ 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(:content)
57
+ end
58
+ end
@@ -0,0 +1,58 @@
1
+ class UsersController < ApplicationController
2
+ before_action :set_user, only: [:show, :edit, :update, :destroy]
3
+
4
+ # GET /users
5
+ def index
6
+ @users = User.all
7
+ end
8
+
9
+ # GET /users/1
10
+ def show
11
+ end
12
+
13
+ # GET /users/new
14
+ def new
15
+ @user = User.new
16
+ end
17
+
18
+ # GET /users/1/edit
19
+ def edit
20
+ end
21
+
22
+ # POST /users
23
+ def create
24
+ @user = User.new(user_params)
25
+
26
+ if @user.save
27
+ redirect_to @user, notice: 'User was successfully created.'
28
+ else
29
+ render :new
30
+ end
31
+ end
32
+
33
+ # PATCH/PUT /users/1
34
+ def update
35
+ if @user.update(user_params)
36
+ redirect_to @user, notice: 'User was successfully updated.'
37
+ else
38
+ render :edit
39
+ end
40
+ end
41
+
42
+ # DELETE /users/1
43
+ def destroy
44
+ @user.destroy
45
+ redirect_to users_url, notice: 'User was successfully destroyed.'
46
+ end
47
+
48
+ private
49
+ # Use callbacks to share common setup or constraints between actions.
50
+ def set_user
51
+ @user = User.find(params[:id])
52
+ end
53
+
54
+ # Only allow a trusted parameter "white list" through.
55
+ def user_params
56
+ params.require(:user).permit(:name)
57
+ end
58
+ end
@@ -0,0 +1,2 @@
1
+ module ApplicationHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module CommentsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module PostsHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ module UsersHelper
2
+ end
@@ -0,0 +1,2 @@
1
+ class Comment < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class Post < ActiveRecord::Base
2
+ end
@@ -0,0 +1,2 @@
1
+ class User < ActiveRecord::Base
2
+ end
@@ -0,0 +1,25 @@
1
+ <%= form_for(@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 |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :content %><br>
16
+ <%= f.text_field :content %>
17
+ </div>
18
+ <div class="field">
19
+ <%= f.label :post_id %><br>
20
+ <%= f.number_field :post_id %>
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', @comment %> |
6
+ <%= link_to 'Back', comments_path %>
@@ -0,0 +1,29 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <h1>Listing Comments</h1>
4
+
5
+ <table>
6
+ <thead>
7
+ <tr>
8
+ <th>Content</th>
9
+ <th>Post</th>
10
+ <th colspan="3"></th>
11
+ </tr>
12
+ </thead>
13
+
14
+ <tbody>
15
+ <% @comments.each do |comment| %>
16
+ <tr>
17
+ <td><%= comment.content %></td>
18
+ <td><%= comment.post_id %></td>
19
+ <td><%= link_to 'Show', comment %></td>
20
+ <td><%= link_to 'Edit', edit_comment_path(comment) %></td>
21
+ <td><%= link_to 'Destroy', comment, method: :delete, data: { confirm: 'Are you sure?' } %></td>
22
+ </tr>
23
+ <% end %>
24
+ </tbody>
25
+ </table>
26
+
27
+ <br>
28
+
29
+ <%= link_to 'New Comment', new_comment_path %>
@@ -0,0 +1,5 @@
1
+ <h1>New Comment</h1>
2
+
3
+ <%= render 'form' %>
4
+
5
+ <%= link_to 'Back', comments_path %>
@@ -0,0 +1,14 @@
1
+ <p id="notice"><%= notice %></p>
2
+
3
+ <p>
4
+ <strong>Content:</strong>
5
+ <%= @comment.content %>
6
+ </p>
7
+
8
+ <p>
9
+ <strong>Post:</strong>
10
+ <%= @comment.post_id %>
11
+ </p>
12
+
13
+ <%= link_to 'Edit', edit_comment_path(@comment) %> |
14
+ <%= link_to 'Back', comments_path %>
@@ -0,0 +1,14 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>Dummy</title>
5
+ <%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
6
+ <%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
7
+ <%= csrf_meta_tags %>
8
+ </head>
9
+ <body>
10
+
11
+ <%= yield %>
12
+
13
+ </body>
14
+ </html>
@@ -0,0 +1,21 @@
1
+ <%= form_for(@post) do |f| %>
2
+ <% if @post.errors.any? %>
3
+ <div id="error_explanation">
4
+ <h2><%= pluralize(@post.errors.count, "error") %> prohibited this post from being saved:</h2>
5
+
6
+ <ul>
7
+ <% @post.errors.full_messages.each do |message| %>
8
+ <li><%= message %></li>
9
+ <% end %>
10
+ </ul>
11
+ </div>
12
+ <% end %>
13
+
14
+ <div class="field">
15
+ <%= f.label :content %><br>
16
+ <%= f.text_field :content %>
17
+ </div>
18
+ <div class="actions">
19
+ <%= f.submit %>
20
+ </div>
21
+ <% end %>