質問編集履歴

3

routes.rbを追記

2020/05/18 08:28

投稿

mamiduka
mamiduka

スコア11

test CHANGED
File without changes
test CHANGED
@@ -95,3 +95,29 @@
95
95
  end
96
96
 
97
97
  ```
98
+
99
+
100
+
101
+ ```
102
+
103
+ routes.rb
104
+
105
+
106
+
107
+ Rails.application.routes.draw do
108
+
109
+ devise_for :users
110
+
111
+ resources :homes, only: :index
112
+
113
+ root to: 'homes#index'
114
+
115
+ resources :users, only: :show do
116
+
117
+ resources :events
118
+
119
+ end
120
+
121
+ end
122
+
123
+ ```

2

プライベートの追加

2020/05/18 08:28

投稿

mamiduka
mamiduka

スコア11

test CHANGED
File without changes
test CHANGED
@@ -84,4 +84,14 @@
84
84
 
85
85
  end
86
86
 
87
+
88
+
89
+ private
90
+
91
+ def event_params
92
+
93
+ params.require(:event).permit(:worker_name, :description, :start_date, :end_date).merge(user_id: current_user.id)
94
+
95
+ end
96
+
87
97
  ```

1

eventコントローラーの記述の追加

2020/05/18 05:20

投稿

mamiduka
mamiduka

スコア11

test CHANGED
File without changes
test CHANGED
@@ -45,3 +45,43 @@
45
45
  必要な参照ファイルが他にあればご連絡ください。
46
46
 
47
47
  よろしくお願いいたします。
48
+
49
+
50
+
51
+
52
+
53
+ ```
54
+
55
+ events_controller.rb
56
+
57
+
58
+
59
+
60
+
61
+ def create
62
+
63
+ @event = Event.new(event_params)
64
+
65
+
66
+
67
+ respond_to do |format|
68
+
69
+ if @event.save
70
+
71
+ format.html { redirect_to @event, notice: 'Event was successfully created.' }
72
+
73
+ format.json { render :show, status: :created, location: @event }
74
+
75
+ else
76
+
77
+ format.html { render :new }
78
+
79
+ format.json { render json: @event.errors, status: :unprocessable_entity }
80
+
81
+ end
82
+
83
+ end
84
+
85
+ end
86
+
87
+ ```