teratail header banner
teratail header banner
質問するログイン新規登録

質問編集履歴

1

<code>に変更

2020/02/11 13:14

投稿

H.T.
H.T.

スコア5

title CHANGED
File without changes
body CHANGED
@@ -2,12 +2,125 @@
2
2
  postはされているのですがどこが理解出来ていないのかわかっていない状況です
3
3
  お力添え頂けると幸いです!
4
4
 
5
+ ```ここに言語を入力
5
- ![![![イメージ](d993908dbc0e51909b8ef841ba4c819e.png)](8f7b6b8d7d7d6e15c7ba267ec597d1ce.png)
6
+ class UsersController < ApplicationController
6
7
 
8
+ def index
9
+ @users = User.all
7
- ![イメージ説明](28a53ae4e6b03dffebb09a12d446cb41.png)
10
+ @user = User.new
11
+ end
8
12
 
13
+ def show
9
- ![イメージ説明](72654ae64f17439b63c768c0bd1e9461.png)
14
+ @user = User.find(params[:id])
15
+ end
10
16
 
17
+ def new
11
- ![イメージ説明](ac93c95ec6dec3f8b0e899785bac9b0c.png)
18
+ @user = User.new
19
+ end
12
20
 
21
+ def create
22
+ @user = User.new(user_params)
23
+ if @user.save
24
+ redirect_to user_path(@user)
25
+ else
26
+ render :new
27
+ end
28
+ end
29
+
30
+ def edit
31
+ @user = User.find(params[:id])
32
+ end
33
+
34
+ def update
35
+ @user = User.find(params[:id])
36
+ if @user.update(user_params)
37
+ redirect_to user_path(@user)
38
+ else
39
+ render :edit
40
+ end
41
+ end
42
+
43
+ def library
44
+ end
45
+
46
+ private
47
+
48
+ def user_params
49
+ params.require(:user).permit(:id, :name, :img, :email, :password, :password_confirmation)
50
+ end
51
+
52
+ def after_sign_up_path_for(resource)
13
- ![イメージ説明](9f7f5f60c314bc1a2bf8b5bc3b301d0d.png)
53
+ "/user/#{current_user.id}"
54
+ end
55
+
56
+ def after_sign_out_path_for(resource)
57
+ users_index_path
58
+ end
59
+
60
+ end
61
+
62
+ ```
63
+
64
+
65
+ ```ここに言語を入力
66
+ (<% provide(:title, "Edit user") %>
67
+
68
+ <div class="py-4">
69
+ <div class="container">
70
+ <h1 class="text-center">Update your profile</h1>
71
+ <div class="row justify-content-center">
72
+ <div class="col-md-6 col-md-offset-3">
73
+
74
+ <%= form_with model: @user, url: { action: "update" } do |f| %>
75
+ <%= f.label :name %>
76
+ <%= f.text_field :name, class: 'form-control' %>
77
+
78
+ <%= f.label :email %>
79
+ <%= f.email_field :email, class: 'form-control' %>
80
+
81
+ <%#= f.label :password, "New password" %>
82
+ <%#= f.password_field :password, class: 'form-control' %>
83
+
84
+ <%#= f.label :password_confirmation, "Confirmation" %>
85
+ <%#= f.password_field :password_confirmation, class: 'form-control' %>
86
+
87
+ <%= f.label :img %>
88
+ <%= f.file_field :img %>
89
+
90
+ <div class="actions">
91
+ <%= f.submit "Save changes", class: "btn btn-primary" %>
92
+ </div>
93
+ <% end %>
94
+ </div>
95
+ </div>
96
+ </div>
97
+ </div>)
98
+ ```
99
+
100
+
101
+
102
+
103
+
104
+ ```ここに言語を入力
105
+ Rails.application.routes.draw do
106
+
107
+ devise_for :users, controllers: { sessions: 'users/sessions' }
108
+
109
+ devise_scope :user do
110
+ get "users/show", :to => "users/user_id#show"
111
+ get "user/id", :to => "users/registration#detail"
112
+ get "signup", :to => "users/registrations#new"
113
+ get "sign_in", :to => "devise/sessions#new"
114
+ get "login", :to => "users/sessions#new"
115
+ end
116
+
117
+ root to: 'pages#index'
118
+
119
+ resources :users
120
+ resources :posts do
121
+ resources :comments, only: [:create]
122
+ end
123
+ get "users/library"
124
+ get "pages/index"
125
+
126
+ end