質問編集履歴

5

改善点

2019/04/19 10:28

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -10,11 +10,11 @@
10
10
 
11
11
 
12
12
 
13
- app/views/plans/index.html.erb
13
+ app/views/home/search.html.erb
14
14
 
15
15
  ![イメージ説明](5af3ac8eb099807494ddad4deb696685.png)
16
16
 
17
- app/views/home/search.html.erb
17
+ app/views/plans/index.html.erb
18
18
 
19
19
  ![イメージ説明](82d707481fcdd7ed86fb1571ae4eb6bf.png)
20
20
 

4

改善点

2019/04/19 10:27

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -4,7 +4,9 @@
4
4
 
5
5
 
6
6
 
7
+
8
+
7
- homeのモデルからplansのカラムを検索して、plansのモデルで表示しようとしています。
9
+ 期待していた挙動は、検索機能を利用して、homeのモデルからplansのtitleカラムを検索して、plansのview検索結果を表示していました。問題のある現在の挙動は、home/searchから検索るとhttp://localhost:3000/plans?utf8=✓&title=kobeと検索されているのですが、結果が出せていない
8
10
 
9
11
 
10
12
 

3

改善点

2019/04/19 10:26

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -6,7 +6,13 @@
6
6
 
7
7
  homeのモデルからplansのカラムを検索して、plansのモデルで表示しようとしています。
8
8
 
9
+
10
+
11
+ app/views/plans/index.html.erb
12
+
9
13
  ![イメージ説明](5af3ac8eb099807494ddad4deb696685.png)
14
+
15
+ app/views/home/search.html.erb
10
16
 
11
17
  ![イメージ説明](82d707481fcdd7ed86fb1571ae4eb6bf.png)
12
18
 

2

改善点

2019/04/19 10:12

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -12,7 +12,7 @@
12
12
 
13
13
 
14
14
 
15
- plans
15
+ app/controllers/plans_controller
16
16
 
17
17
  ```controller
18
18
 
@@ -36,7 +36,7 @@
36
36
 
37
37
 
38
38
 
39
- home
39
+ app/controller/home_controller
40
40
 
41
41
  ```controller
42
42
 
@@ -52,7 +52,7 @@
52
52
 
53
53
 
54
54
 
55
- home
55
+ app/model/home.rb
56
56
 
57
57
  ```model
58
58
 
@@ -80,7 +80,7 @@
80
80
 
81
81
  ```
82
82
 
83
- ```db plans
83
+ ```db/migrate/plans
84
84
 
85
85
  class CreatePlans < ActiveRecord::Migration
86
86
 
@@ -102,7 +102,7 @@
102
102
 
103
103
 
104
104
 
105
- home
105
+ app/views/home/search.html.erb
106
106
 
107
107
  ```view
108
108
 

1

改善点

2019/04/19 10:11

投稿

avicii
avicii

スコア49

test CHANGED
File without changes
test CHANGED
@@ -1,4 +1,6 @@
1
- plansモデルにあるカラムをhomeモデルで検索して、plansに表示したいと思っています。しかし、homeで検索する時に、うまくplansのカラムを集めることができていないか・homeからplansの受け渡しができていないなのかがわからない状態になっています。わかる方がいらたらぞ教えていただきたいで
1
+ plansモデルにあるカラムをhomeモデルで検索して、plansに表示したいと思っています。しかし、homeで検索する時に、うまくplansのカラムを集めることができていないか・homeからplansの受け渡しができていないなのかがわからない状態になっています。(homeモデルで、plansのtitleを検索検索後、plansモデルで表示できるよにしようと思ってい)
2
+
3
+ わかる方がいらしたら、どうぞ教えていただきたいです。
2
4
 
3
5
 
4
6
 
@@ -14,9 +16,21 @@
14
16
 
15
17
  ```controller
16
18
 
19
+ def index
20
+
17
21
  @plans = Plan.includes(:guider).page(params[:page]).per(5).order("created_at DESC")
18
22
 
19
23
  @plans = Plan.page(params[:page]).per(5).order("created_at DESC").search(params[:search])
24
+
25
+ end
26
+
27
+
28
+
29
+ def create
30
+
31
+ Plan.create(place: params[:place], image: params[:image], copy_image: params[:copy_image], second_image: params[:second_image], third_image: params[:third_image], fourth_image: params[:fourth_image], five_image: params[:five_image], title: params[:title], contents: params[:contents], times: params[:times], datetimes: params[:datetimes], guider_id: current_guider.id
32
+
33
+ end
20
34
 
21
35
  ```
22
36
 
@@ -26,9 +40,13 @@
26
40
 
27
41
  ```controller
28
42
 
43
+ def search
44
+
29
45
  @plans = Plan.includes(:guider).page(params[:page]).per(5).order("created_at DESC")
30
46
 
31
47
  @plans = Plan.page(params[:page]).per(5).order("created_at DESC").search(params[:search])
48
+
49
+ end
32
50
 
33
51
  ```
34
52
 
@@ -37,6 +55,8 @@
37
55
  home
38
56
 
39
57
  ```model
58
+
59
+ class Home < ActiveRecord::Base
40
60
 
41
61
  belongs_to :plan
42
62
 
@@ -56,6 +76,28 @@
56
76
 
57
77
  end
58
78
 
79
+ end
80
+
81
+ ```
82
+
83
+ ```db plans
84
+
85
+ class CreatePlans < ActiveRecord::Migration
86
+
87
+ def change
88
+
89
+ create_table :plans do |t|
90
+
91
+ t.text :title
92
+
93
+ t.timestamps null: false
94
+
95
+ end
96
+
97
+ end
98
+
99
+ end
100
+
59
101
  ```
60
102
 
61
103