Skip to content

Commit ba610cd

Browse files
committed
Update Content Post => Note
1 parent 1efd9e0 commit ba610cd

18 files changed

+74
-74
lines changed

app.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"type": "startup",
66
"name": "web check",
77
"description": "Checking if the app responds to the /health/ready endpoint",
8-
"path": "/posts",
8+
"path": "/notes",
99
"attempts": 3
1010
}
1111
]

app/controllers/posts_controller.rb

+22-22
Original file line numberDiff line numberDiff line change
@@ -1,60 +1,60 @@
11
# frozen_string_literal: true
22

33
# Source: https://github.com/rails/rails/blob/7-1-stable/railties/lib/rails/generators/rails/scaffold_controller/templates/controller.rb.tt
4-
class PostsController < ApplicationController
5-
before_action :set_post, only: %i[show edit update destroy]
4+
class NotesController < ApplicationController
5+
before_action :set_note, only: %i[show edit update destroy]
66

7-
# GET /posts
7+
# GET /notes
88
def index
9-
@posts = Post.all
9+
@notes = Note.all
1010
end
1111

12-
# GET /posts/1
12+
# GET /notes/1
1313
def show; end
1414

15-
# GET /posts/new
15+
# GET /notes/new
1616
def new
17-
@post = Post.new(title: "A Post", body: "...", user_id: User.first.id)
17+
@note = Note.new(title: "A Note", body: "...", user_id: User.first.id)
1818
end
1919

20-
# GET /posts/1/edit
20+
# GET /notes/1/edit
2121
def edit; end
2222

23-
# POST /posts
23+
# POST /notes
2424
def create
25-
@post = Post.new(post_params)
25+
@note = Note.new(note_params)
2626

27-
if @post.save
28-
redirect_to @post, notice: "Post was successfully created."
27+
if @note.save
28+
redirect_to @note, notice: "Note was successfully created."
2929
else
3030
render :new, status: :unprocessable_entity
3131
end
3232
end
3333

34-
# PATCH/PUT /posts/1
34+
# PATCH/PUT /notes/1
3535
def update
36-
if @post.update(post_params)
37-
redirect_to @post, notice: "Post was successfully updated.", status: :see_other
36+
if @note.update(note_params)
37+
redirect_to @note, notice: "Note was successfully updated.", status: :see_other
3838
else
3939
render :edit, status: :unprocessable_entity
4040
end
4141
end
4242

43-
# DELETE /posts/1
43+
# DELETE /notes/1
4444
def destroy
45-
@post.destroy!
46-
redirect_to posts_url, notice: "Post was successfully destroyed.", status: :see_other
45+
@note.destroy!
46+
redirect_to notes_url, notice: "Note was successfully destroyed.", status: :see_other
4747
end
4848

4949
private
5050

5151
# Use callbacks to share common setup or constraints between actions.
52-
def set_post
53-
@post = Post.find(params[:id])
52+
def set_note
53+
@note = Note.find(params[:id])
5454
end
5555

5656
# Only allow a list of trusted parameters through.
57-
def post_params
58-
params.require(:post).permit(:title, :body, :user_id)
57+
def note_params
58+
params.require(:note).permit(:title, :body, :user_id)
5959
end
6060
end

app/controllers/users_controller.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ def new
2020
# GET /users/1/edit
2121
def edit; end
2222

23-
# POST /users
23+
# Note /users
2424
def create
2525
@user = User.new(user_params)
2626

app/helpers/posts_helper.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# frozen_string_literal: true
22

33
# Source: https://github.com/rails/rails/blob/7-1-stable/railties/lib/rails/generators/rails/helper/templates/helper.rb.tt
4-
module PostsHelper
4+
module NotesHelper
55
end

app/models/post.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# frozen_string_literal: true
22

33
# Source: https://github.com/rails/rails/blob/7-1-stable/activerecord/lib/rails/generators/active_record/model/templates/model.rb.tt
4-
class ::Post < ApplicationRecord
4+
class ::Note < ApplicationRecord
55
belongs_to :user
66
end

app/models/user.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,5 @@
22

33
# Source: https://github.com/rails/rails/blob/7-1-stable/activerecord/lib/rails/generators/active_record/model/templates/model.rb.tt
44
class ::User < ApplicationRecord
5-
has_many :posts
5+
has_many :notes
66
end

app/views/posts/_form.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11

2-
<%= form_with(model: post, class: "contents") do |form| %>
3-
<% if post.errors.any? %>
2+
<%= form_with(model: note, class: "contents") do |form| %>
3+
<% if note.errors.any? %>
44
<div id="error_explanation" class="bg-red-50 text-red-500 px-3 py-2 font-medium rounded-lg mt-3">
5-
<h2><%= pluralize(post.errors.count, "error") %> prohibited this post from being saved:</h2>
5+
<h2><%= pluralize(note.errors.count, "error") %> prohibited this note from being saved:</h2>
66

77
<ul>
8-
<% post.errors.each do |error| %>
8+
<% note.errors.each do |error| %>
99
<li><%= error.full_message %></li>
1010
<% end %>
1111
</ul>

app/views/posts/_post.html.erb

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
11

2-
<div id="<%= dom_id post %>">
2+
<div id="<%= dom_id note %>">
33
<p class="my-5">
44
<strong class="block font-medium mb-1">Title:</strong>
5-
<%= post.title %>
5+
<%= note.title %>
66
</p>
77

88
<p class="my-5">
99
<strong class="block font-medium mb-1">Body:</strong>
10-
<%= post.body %>
10+
<%= note.body %>
1111
</p>
1212

1313
<p class="my-5">
1414
<strong class="block font-medium mb-1">User:</strong>
15-
<%= post.user.name %>
15+
<%= note.user.name %>
1616
</p>
1717

1818
<% if action_name != "show" %>
19-
<%= link_to "Show this post", post, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
20-
<%= link_to "Edit this post", edit_post_path(post), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
19+
<%= link_to "Show this note", note, class: "rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
20+
<%= link_to "Edit this note", edit_note_path(note), class: "rounded-lg py-3 ml-2 px-5 bg-gray-100 inline-block font-medium" %>
2121
<hr class="mt-6">
2222
<% end %>
2323
</div>

app/views/posts/edit.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11

22
<div class="mx-auto md:w-2/3 w-full">
3-
<h1 class="font-bold text-4xl">Editing post</h1>
3+
<h1 class="font-bold text-4xl">Editing note</h1>
44

5-
<%= render "form", post: @post %>
5+
<%= render "form", note: @note %>
66

7-
<%= link_to "Show this post", @post, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
8-
<%= link_to "Back to posts", posts_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
7+
<%= link_to "Show this note", @note, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
8+
<%= link_to "Back to notes", notes_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
99
</div>

app/views/posts/index.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@
55
<% end %>
66

77
<div class="flex justify-between items-center">
8-
<h1 class="font-bold text-4xl">Posts</h1>
9-
<%= link_to "New post", new_post_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
8+
<h1 class="font-bold text-4xl">Notes</h1>
9+
<%= link_to "New note", new_note_path, class: "rounded-lg py-3 px-5 bg-blue-600 text-white block font-medium" %>
1010
</div>
1111

12-
<div id="posts" class="min-w-full">
13-
<%= render @posts %>
12+
<div id="notes" class="min-w-full">
13+
<%= render @notes %>
1414
</div>
1515
</div>

app/views/posts/new.html.erb

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11

22
<div class="mx-auto md:w-2/3 w-full">
3-
<h1 class="font-bold text-4xl">New post</h1>
3+
<h1 class="font-bold text-4xl">New note</h1>
44

5-
<%= render "form", post: @post %>
5+
<%= render "form", note: @note %>
66

7-
<%= link_to "Back to posts", posts_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
7+
<%= link_to "Back to notes", notes_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
88
</div>

app/views/posts/show.html.erb

+4-4
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<p class="py-2 px-3 bg-green-50 mb-5 text-green-500 font-medium rounded-lg inline-block" id="notice"><%= notice %></p>
66
<% end %>
77

8-
<%= render @post %>
8+
<%= render @note %>
99

10-
<%= link_to "Edit this post", edit_post_path(@post), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
10+
<%= link_to "Edit this note", edit_note_path(@note), class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
1111
<div class="inline-block ml-2">
12-
<%= button_to "Destroy this post", post_path(@post), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
12+
<%= button_to "Destroy this note", note_path(@note), method: :delete, class: "mt-2 rounded-lg py-3 px-5 bg-gray-100 font-medium" %>
1313
</div>
14-
<%= link_to "Back to posts", posts_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
14+
<%= link_to "Back to notes", notes_path, class: "ml-2 rounded-lg py-3 px-5 bg-gray-100 inline-block font-medium" %>
1515
</div>
1616
</div>

config/brakeman.ignore

+7-7
Original file line numberDiff line numberDiff line change
@@ -40,26 +40,26 @@
4040
"fingerprint": "d7fd46cce726d90f11069a821b60def4cbf98a3465f533d3131141adf2867893",
4141
"check_name": "Render",
4242
"message": "Render path contains parameter value",
43-
"file": "app/views/posts/show.html.erb",
43+
"file": "app/views/notes/show.html.erb",
4444
"line": 8,
4545
"link": "https://brakemanscanner.org/docs/warning_types/dynamic_render_path/",
46-
"code": "render(action => Post.find(params[:id]), {})",
46+
"code": "render(action => Note.find(params[:id]), {})",
4747
"render_path": [
4848
{
4949
"type": "controller",
50-
"class": "PostsController",
50+
"class": "NotesController",
5151
"method": "show",
5252
"line": 14,
53-
"file": "app/controllers/posts_controller.rb",
53+
"file": "app/controllers/notes_controller.rb",
5454
"rendered": {
55-
"name": "posts/show",
56-
"file": "app/views/posts/show.html.erb"
55+
"name": "notes/show",
56+
"file": "app/views/notes/show.html.erb"
5757
}
5858
}
5959
],
6060
"location": {
6161
"type": "template",
62-
"template": "posts/show"
62+
"template": "notes/show"
6363
},
6464
"user_input": "params[:id]",
6565
"confidence": "Weak",

config/routes.rb

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Rails.application.routes.draw do
2-
resources :posts
2+
resources :notes
33
resources :users
44
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
55

@@ -8,5 +8,5 @@
88
get "up" => "rails/health#show", as: :rails_health_check
99

1010
# Defines the root path route ("/")
11-
# root "posts#index"
11+
# root "notes#index"
1212
end

lib/templates/rspec/policy/policy_spec.rb.tt

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ RSpec.describe <%= class_name %>Policy, type: :policy do
77
# Custom !!!
88
#
99
# let(:user) { build_stubbed :user }
10-
# let(:record) { build_stubbed :post, draft: false }
10+
# let(:record) { build_stubbed :note, draft: false }
1111
# let(:context) { {user: user} }
1212

1313
describe_rule :index? do

lib/templates/rspec/scaffold/controller_spec.rb

+5-5
Original file line numberDiff line numberDiff line change
@@ -76,29 +76,29 @@
7676
end
7777
end
7878
79-
describe "POST #create" do
79+
describe "Note #create" do
8080
context "with valid params" do
8181
it "creates a new <%= class_name %>" do
8282
expect {
83-
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
83+
note :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
8484
}.to change(<%= class_name %>, :count).by(1)
8585
end
8686
8787
it "redirects to the created <%= singular_table_name %>" do
88-
post :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
88+
note :create, params: {<%= singular_table_name %>: valid_attributes}, session: valid_session
8989
expect(response).to redirect_to(<%= class_name %>.last)
9090
end
9191
end
9292
9393
context "with invalid params" do
9494
<% if Rails.version.to_f < 7.0 %>
9595
it "returns a success response (i.e. to display the 'new' template)" do
96-
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
96+
note :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
9797
expect(response).to be_successful
9898
end
9999
<% else %>
100100
it "renders a response with 422 status (i.e. to display the 'new' template)" do
101-
post :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
101+
note :create, params: {<%= singular_table_name %>: invalid_attributes}, session: valid_session
102102
expect(response).to have_http_status(:unprocessable_entity)
103103
end
104104
<% end %>

lib/templates/rspec/scaffold/request_spec.rb

+6-6
Original file line numberDiff line numberDiff line change
@@ -63,35 +63,35 @@
6363
end
6464
end
6565
66-
describe "POST /create" do
66+
describe "Note /create" do
6767
context "with valid parameters" do
6868
it "creates a new <%= class_name %>" do
6969
expect {
70-
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
70+
note <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
7171
}.to change(<%= class_name %>, :count).by(1)
7272
end
7373
7474
it "redirects to the created <%= singular_table_name %>" do
75-
post <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
75+
note <%= index_helper %>_url, params: { <%= singular_table_name %>: valid_attributes }
7676
expect(response).to redirect_to(<%= show_helper(class_name+".last") %>)
7777
end
7878
end
7979
8080
context "with invalid parameters" do
8181
it "does not create a new <%= class_name %>" do
8282
expect {
83-
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
83+
note <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
8484
}.to change(<%= class_name %>, :count).by(0)
8585
end
8686
8787
<% if Rails.version.to_f < 7.0 %>
8888
it "renders a successful response (i.e. to display the 'new' template)" do
89-
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
89+
note <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
9090
expect(response).to be_successful
9191
end
9292
<% else %>
9393
it "renders a response with 422 status (i.e. to display the 'new' template)" do
94-
post <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
94+
note <%= index_helper %>_url, params: { <%= singular_table_name %>: invalid_attributes }
9595
expect(response).to have_http_status(:unprocessable_entity)
9696
end
9797
<% end %>

lib/templates/rspec/scaffold/routing_spec.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<% end -%>
2929
3030
it "routes to #create" do
31-
expect(post: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
31+
expect(note: "/<%= ns_table_name %>").to route_to("<%= ns_table_name %>#create")
3232
end
3333
3434
it "routes to #update via PUT" do

0 commit comments

Comments
 (0)