質問編集履歴
4
変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Rails4
|
1
|
+
Rails4 お問い合わせの設計
|
test
CHANGED
@@ -1,13 +1,7 @@
|
|
1
|
-
|
1
|
+
お問い合わせはDBを作って実装すべきでしょうか?
|
2
2
|
|
3
|
-
|
3
|
+
現在は、[DBと関係ないFormを作り](http://qiita.com/tsumekoara/items/787f914497693cb38e6c)お問い合わせを実装しました。
|
4
|
-
|
5
|
-
active_adminでエラーになってしまいます。
|
6
|
-
|
7
|
-
どうしたらよいでしょうか?
|
8
4
|
|
9
5
|
|
10
6
|
|
11
|
-
|
12
|
-
|
13
|
-
|
7
|
+
オークションやクラウドファウディングサイトなサービスを想定しています。
|
3
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,6 +1,8 @@
|
|
1
|
-
|
1
|
+
ApplicationControllerで
|
2
2
|
|
3
|
+
last_access_in_atメソッドをbefore_actionすると
|
4
|
+
|
3
|
-
|
5
|
+
active_adminでエラーになってしまいます。
|
4
6
|
|
5
7
|
どうしたらよいでしょうか?
|
6
8
|
|
2
変更
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
Rails4
|
1
|
+
Rails4 ApplicationControllerにbefore_actionをつけた場合
|
test
CHANGED
@@ -1,105 +1,11 @@
|
|
1
|
-
|
1
|
+
**ボールドテキスト**ApplicationControllerにbefore_actionでlast_access_in_atメソッドを
|
2
2
|
|
3
|
+
実行させるとactive_adminでエラーになってしまいます。
|
3
4
|
|
4
|
-
|
5
|
-
例:
|
6
|
-
|
7
|
-
Profileモデル ユーザネーム(日本語)、自己紹介、画像
|
8
|
-
|
9
|
-
addressモデル 住所情報
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
現状はdeviseで登録したタイミングでbefore_createを使い
|
14
|
-
|
15
|
-
Profileモデルとaddressモデルを生成しています。
|
16
|
-
|
17
|
-
上記のモデルはuser_idでアソシエーションしています。
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
ただbefore_createで生成したモデルのプライマリと
|
22
|
-
|
23
|
-
Deviseモデルのuser_idは絶対的な一意性がないと本日知ったため、作り直したいです。
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
5
|
+
どうしたらよいでしょうか?
|
28
|
-
|
29
|
-
<%= comment.originator.user_name%>としていた部分も
|
30
|
-
|
31
|
-
user_idとProfileモデルのプライマリと一意性がないので修正しなければなりません。。
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
```lang-ruby
|
36
|
-
|
37
|
-
#お知らせ一覧
|
38
|
-
|
39
|
-
#notification Model
|
40
|
-
|
41
|
-
class Notification < ActiveRecord::Base
|
42
|
-
|
43
|
-
belongs_to :originator, class_name: 'Profile', foreign_key: :originator_id
|
44
|
-
|
45
|
-
belongs_to :recipient, class_name: 'Profile', foreign_key: :recipient_id
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
#notification View
|
50
|
-
|
51
|
-
<% @notifications.each do |comment| %>
|
52
|
-
|
53
|
-
<% if comment.body_num == 2 %>
|
54
|
-
|
55
|
-
<a href="<%= item_url(comment.item_id) %>" class="list-group-item">
|
56
|
-
|
57
|
-
 <i class="fa fa-heart-o"></i> 
|
58
|
-
|
59
|
-
<small><%= comment.originator.user_name%>さんが「<%= comment.item.title%>」にXXXしました。</small>
|
60
|
-
|
61
|
-
<p class="palette-paragraph text-right"><i class="fa fa-clock-o"></i> <%=date_format(comment.created_at) %></p>
|
62
|
-
|
63
|
-
</a>
|
64
|
-
|
65
|
-
<% end %>
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
#notification Seed
|
70
|
-
|
71
|
-
class CreateNotifications < ActiveRecord::Migration
|
72
|
-
|
73
|
-
def change
|
74
|
-
|
75
|
-
create_table :notifications do |t|
|
76
|
-
|
77
|
-
t.integer :originator_id
|
78
|
-
|
79
|
-
t.integer :recipient_id
|
80
|
-
|
81
|
-
t.integer :item_id
|
82
|
-
|
83
|
-
t.integer :navi_id
|
84
|
-
|
85
|
-
t.integer :message_id
|
86
|
-
|
87
|
-
t.integer :body_num
|
88
|
-
|
89
|
-
t.boolean :status
|
90
6
|
|
91
7
|
|
92
8
|
|
93
9
|
|
94
10
|
|
95
|
-
|
96
|
-
|
97
|
-
|
11
|
+
![イメージ説明][WIDTH:600](553e25431e08bd87702426e63f30493e.png)
|
98
|
-
|
99
|
-
end
|
100
|
-
|
101
|
-
end
|
102
|
-
|
103
|
-
end
|
104
|
-
|
105
|
-
```
|
1
修正
test
CHANGED
File without changes
|
test
CHANGED
@@ -1,8 +1,8 @@
|
|
1
|
-
Deviseを使って認証を実装した場合
|
1
|
+
Deviseを使って認証を実装した場合、ユーザ情報に紐づく各モデルはどのような設計でアソシエーションするべきでしょうか
|
2
|
-
|
3
|
-
下記のモデルはどのように設計すれば良いでしょうか?
|
4
2
|
|
5
3
|
|
4
|
+
|
5
|
+
例:
|
6
6
|
|
7
7
|
Profileモデル ユーザネーム(日本語)、自己紹介、画像
|
8
8
|
|
@@ -14,20 +14,92 @@
|
|
14
14
|
|
15
15
|
Profileモデルとaddressモデルを生成しています。
|
16
16
|
|
17
|
+
上記のモデルはuser_idでアソシエーションしています。
|
18
|
+
|
19
|
+
|
20
|
+
|
17
21
|
ただbefore_createで生成したモデルのプライマリと
|
18
22
|
|
19
|
-
Deviseモデルのuser_idは絶対的な一意性がない
|
23
|
+
Deviseモデルのuser_idは絶対的な一意性がないと本日知ったため、作り直したいです。
|
20
24
|
|
21
25
|
|
22
26
|
|
23
27
|
作り直したい理由がもう一つあります。
|
24
28
|
|
25
|
-
|
29
|
+
<%= comment.originator.user_name%>としていた部分も
|
30
|
+
|
31
|
+
user_idとProfileモデルのプライマリと一意性がないので修正しなければなりません。。
|
32
|
+
|
33
|
+
|
26
34
|
|
27
35
|
```lang-ruby
|
28
36
|
|
37
|
+
#お知らせ一覧
|
38
|
+
|
39
|
+
#notification Model
|
40
|
+
|
41
|
+
class Notification < ActiveRecord::Base
|
42
|
+
|
43
|
+
belongs_to :originator, class_name: 'Profile', foreign_key: :originator_id
|
44
|
+
|
45
|
+
belongs_to :recipient, class_name: 'Profile', foreign_key: :recipient_id
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
#notification View
|
50
|
+
|
51
|
+
<% @notifications.each do |comment| %>
|
52
|
+
|
29
|
-
<%
|
53
|
+
<% if comment.body_num == 2 %>
|
54
|
+
|
55
|
+
<a href="<%= item_url(comment.item_id) %>" class="list-group-item">
|
56
|
+
|
57
|
+
 <i class="fa fa-heart-o"></i> 
|
58
|
+
|
59
|
+
<small><%= comment.originator.user_name%>さんが「<%= comment.item.title%>」にXXXしました。</small>
|
60
|
+
|
61
|
+
<p class="palette-paragraph text-right"><i class="fa fa-clock-o"></i> <%=date_format(comment.created_at) %></p>
|
62
|
+
|
63
|
+
</a>
|
64
|
+
|
65
|
+
<% end %>
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
#notification Seed
|
70
|
+
|
71
|
+
class CreateNotifications < ActiveRecord::Migration
|
72
|
+
|
73
|
+
def change
|
74
|
+
|
75
|
+
create_table :notifications do |t|
|
76
|
+
|
77
|
+
t.integer :originator_id
|
78
|
+
|
79
|
+
t.integer :recipient_id
|
80
|
+
|
81
|
+
t.integer :item_id
|
82
|
+
|
83
|
+
t.integer :navi_id
|
84
|
+
|
85
|
+
t.integer :message_id
|
86
|
+
|
87
|
+
t.integer :body_num
|
88
|
+
|
89
|
+
t.boolean :status
|
90
|
+
|
91
|
+
|
92
|
+
|
93
|
+
|
94
|
+
|
95
|
+
|
96
|
+
|
97
|
+
t.timestamps
|
98
|
+
|
99
|
+
end
|
100
|
+
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
30
104
|
|
31
105
|
```
|
32
|
-
|
33
|
-
これに関してもuser_idとProfileモデルのプライマリと一意性がないので修正しなければなりません。。
|