質問編集履歴

1

userコントローラの記述とコードの名前を追記しました。

2023/08/24 15:31

投稿

sarasa
sarasa

スコア2

test CHANGED
File without changes
test CHANGED
@@ -11,7 +11,6 @@
11
11
  ### 該当するソースコード
12
12
  ```ruby
13
13
  class BooksController < ApplicationController
14
-
15
14
  def create
16
15
  @user = current_user
17
16
  @books = Book.all
@@ -31,7 +30,6 @@
31
30
  @book = Book.new
32
31
  @books = Book.all
33
32
  @book_new = Book.new
34
-
35
33
  end
36
34
 
37
35
  def show
@@ -46,13 +44,33 @@
46
44
  def book_params
47
45
  params.require(:book).permit(:title, :body)
48
46
  end
47
+ end
48
+ ```
49
+ ```ruby
50
+ class UsersController < ApplicationController
51
+ def index
52
+ @user = current_user
53
+ @users = User.all
54
+ @book_new = Book.new
55
+ end
49
56
 
57
+ def show
58
+ @user = current_user
59
+ @book =Book.new
60
+ @book_new = Book.new
61
+ @user = User.find(params[:id])
62
+ @books = @user.books
63
+ end
64
+ :
65
+ :
66
+ :
67
+ private
68
+ def user_params
69
+ params.require(:user).permit(:name, :profile_image, :introduction)
70
+ end
50
71
  end
51
-
52
-
53
72
  ```
54
-
73
+ 投稿詳細画面(books/show)
55
-
56
74
  ```ruby
57
75
 
58
76
  <%= render 'books/list', books: @books, user: @user %>
@@ -79,9 +97,9 @@
79
97
  </div>
80
98
  </div>
81
99
  ```
100
+ booksの部分テンプレート(books_list)
82
101
  ```ruby
83
102
  <p id="notice"><%= flash[:notice] %></p>
84
-
85
103
  <div class='container px-5 px-sm-0'>
86
104
  <div class='row'>
87
105
  <div class='col-md-3'>
@@ -108,7 +126,6 @@
108
126
  <% end %>
109
127
  </div>
110
128
 
111
-
112
129
  <h2 class="mt-3">New book</h2>
113
130
  <%= form_with model: @book_new, local: true do |f| %>
114
131
  <div class = "form-group">