|
1 | 1 | # frozen_string_literal: true
|
2 | 2 |
|
3 | 3 | # 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] |
6 | 6 |
|
7 |
| - # GET /posts |
| 7 | + # GET /notes |
8 | 8 | def index
|
9 |
| - @posts = Post.all |
| 9 | + @notes = Note.all |
10 | 10 | end
|
11 | 11 |
|
12 |
| - # GET /posts/1 |
| 12 | + # GET /notes/1 |
13 | 13 | def show; end
|
14 | 14 |
|
15 |
| - # GET /posts/new |
| 15 | + # GET /notes/new |
16 | 16 | 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) |
18 | 18 | end
|
19 | 19 |
|
20 |
| - # GET /posts/1/edit |
| 20 | + # GET /notes/1/edit |
21 | 21 | def edit; end
|
22 | 22 |
|
23 |
| - # POST /posts |
| 23 | + # POST /notes |
24 | 24 | def create
|
25 |
| - @post = Post.new(post_params) |
| 25 | + @note = Note.new(note_params) |
26 | 26 |
|
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." |
29 | 29 | else
|
30 | 30 | render :new, status: :unprocessable_entity
|
31 | 31 | end
|
32 | 32 | end
|
33 | 33 |
|
34 |
| - # PATCH/PUT /posts/1 |
| 34 | + # PATCH/PUT /notes/1 |
35 | 35 | 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 |
38 | 38 | else
|
39 | 39 | render :edit, status: :unprocessable_entity
|
40 | 40 | end
|
41 | 41 | end
|
42 | 42 |
|
43 |
| - # DELETE /posts/1 |
| 43 | + # DELETE /notes/1 |
44 | 44 | 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 |
47 | 47 | end
|
48 | 48 |
|
49 | 49 | private
|
50 | 50 |
|
51 | 51 | # 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]) |
54 | 54 | end
|
55 | 55 |
|
56 | 56 | # 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) |
59 | 59 | end
|
60 | 60 | end
|
0 commit comments