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

質問編集履歴

3

profile_controller.rbを追加

2019/06/28 10:04

投稿

kulkul
kulkul

スコア12

title CHANGED
File without changes
body CHANGED
@@ -1,4 +1,6 @@
1
+ ```ここに言語を入力
2
+ コード
1
- ### 前提・実現したいこと
3
+ ```### 前提・実現したいこと
2
4
  railsでWEBアプリケーションを開発中にエラーが発生してしまった。
3
5
  これを解決したい。
4
6
 
@@ -68,4 +70,24 @@
68
70
  render("login_form")
69
71
  end
70
72
  end
73
+ ```
74
+ profile_controller.rb
75
+ ```ここに言語を入力
76
+ def create
77
+ @profile = Profile2.find_by(id: params[:id])
78
+ @profile.name = params[:name],
79
+ @profile.department = params[:department],
80
+ @profile.year = params[:year],
81
+ @profile.comment = params[:comment],
82
+ @profile.contact_info = params[:contact_info],
83
+ @profile.skill = params[:skill]
84
+
85
+ if @profile.save
86
+ session[:user_id] = @profile.id
87
+ flash[:notice] = "プロフィール登録が完了しました"
88
+ redirect_to("/profile2s/#{@profile.id}")
89
+ else
90
+ render("profiles/new")
91
+ end
92
+ end
71
93
  ```

2

user_controller.rbの追加

2019/06/28 10:04

投稿

kulkul
kulkul

スコア12

title CHANGED
File without changes
body CHANGED
File without changes

1

user_controller.rbを追加しました。

2019/06/28 08:20

投稿

kulkul
kulkul

スコア12

title CHANGED
File without changes
body CHANGED
@@ -31,4 +31,41 @@
31
31
  render("projects/new")
32
32
  end
33
33
  end
34
+ ```
35
+
36
+ user_controller.rb
37
+ ```
38
+ def create
39
+ @user = User.new(
40
+ email: params[:email],
41
+ password: params[:password]
42
+ )
43
+
44
+ @profile = Profile2.new(
45
+ id: @user.id
46
+ )
47
+
48
+ if @user.save && @profile.save
49
+ session[:user_id] = @user.id
50
+ flash[:notice] = "ユーザー登録が完了しました"
51
+ redirect_to("/profiles/#{@user.id}")
52
+ else
53
+ render("signup")
54
+ end
55
+ end
56
+
57
+ def login
58
+ @user = User.find_by(email: params[:email])
59
+
60
+ if @user
61
+ session[:user_id] = @user.id
62
+ flash[:notice] = "ログインしました"
63
+ redirect_to("/profiles/#{@user.id}")
64
+ else
65
+ @errors_messages = "メールアドレスまたはパスワードが間違っています"
66
+ @email = params[:email]
67
+ @password = params[:password]
68
+ render("login_form")
69
+ end
70
+ end
34
71
  ```