質問編集履歴

1

途中で誤って投稿してしまったため、書いていなかった部分を追記しました。

2022/04/16 14:36

投稿

harukome
harukome

スコア26

test CHANGED
File without changes
test CHANGED
@@ -29,7 +29,7 @@
29
29
  ```
30
30
 
31
31
  ### 該当のソースコード
32
- ユーザー一覧のviewページ
32
+ 1,ユーザー一覧のviewページ
33
33
  ```views/others/index.html.erb
34
34
  <h3>他のユーザー一覧</h3>
35
35
  <p>
@@ -41,7 +41,7 @@
41
41
  <% end %>
42
42
  </p>
43
43
  ```
44
- 選択したユーザーの投稿一覧viewページ
44
+ 2,選択したユーザーの投稿一覧viewページ
45
45
  ```views/posts/index_public.html.erb
46
46
  <div class="posts-container">
47
47
  <% @posts.each do |t| %>
@@ -52,22 +52,38 @@
52
52
  <% end %>
53
53
  </div>
54
54
  ```
55
- コントローラー
55
+ 3,コントローラー
56
- ```others_controller
56
+ ```others_controller.rb
57
57
  def index
58
58
  @users = User.where.not(id: current_user.id)
59
59
  @current_user = User.find_by(id: current_user.id)
60
60
  end
61
61
  ```
62
62
 
63
- ```
63
+ ```posts_controller.rb
64
- def index_public
64
+ def index_public
65
65
  @posts = Post.where(params[:id]).where(setting: "true").order(date: "ASC")
66
66
  end
67
67
  ```
68
+ 4,ルーティング
69
+ ```routes.rb
70
+ resources :posts do
71
+ resources :likes, only: [:create, :destroy]
72
+ collection do
73
+ get :index_private, controller: 'posts', action: 'index_private'
74
+ get :index_public, controller: 'posts', action: 'index_public'
75
+ end
76
+ member do
77
+ get :show_private, controller: 'posts', action: 'show_private'
78
+ get :show_public, controller: 'posts', action: 'show_public'
79
+ end
80
+ end
81
+
82
+ get 'others/index' => 'others#index'
83
+ ```
84
+
68
85
  ### 試したこと
69
-
70
- ここに問題に対し試したことを記載しださい。
86
+ user_idがうまく渡せいないのではないか考え、ルーティングの「get :index_public, controller: 'posts', action: 'index_public'」の部分member doの方に記載場所を変更たのですがうまくいきませんでした
71
87
 
72
88
  ### 補足情報(FW/ツールのバージョンなど)
73
89