質問編集履歴
1
user.rbを加えました。
test
CHANGED
@@ -1 +1 @@
|
|
1
|
-
rails 管理者が他
|
1
|
+
rails 管理者が他者の情報を変更できない
|
test
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
管理者が特定の人材の情報を変更しようとしても、パスワードが要求されます。
|
3
3
|
例えば、下記の良いうに管理者だけが、imagを変更できるとして、変更したあと
|
4
4
|
passwordが聞かれます。パスワードは個人しかわからないので、どうしたら良いかわかりません。
|
5
|
-
個人は、逆パスワードの変更のみできるようにしています。
|
5
|
+
個人は、逆にパスワードの変更のみできるようにしています。
|
6
6
|
ご教授いただけると幸いです。
|
7
7
|
|
8
8
|
```ruby on rails
|
@@ -32,3 +32,49 @@
|
|
32
32
|
</div>
|
33
33
|
<% end %>
|
34
34
|
```
|
35
|
+
|
36
|
+
user.rb収載のご要望がありましたので下記に収載します。
|
37
|
+
なお、このご指摘で、# validates :password, presence: trueをコメントアウトすることで、
|
38
|
+
パスワードが要求されず変更することができるようになりました。
|
39
|
+
ただ、validatesの意味がよくわからなくなってきました。
|
40
|
+
アドバイスがあれば幸いです。
|
41
|
+
|
42
|
+
```ruby on rails
|
43
|
+
class User < ApplicationRecord
|
44
|
+
has_secure_password
|
45
|
+
has_one_attached :image, dependent: :destroy
|
46
|
+
|
47
|
+
validates :name, presence: true
|
48
|
+
validates :email, presence: true, uniqueness:true
|
49
|
+
# validates :password, presence: true
|
50
|
+
|
51
|
+
scope :recent, -> { order(created_at: :desc) }
|
52
|
+
|
53
|
+
has_many :posts, dependent: :destroy
|
54
|
+
has_many :careers, dependent: :destroy
|
55
|
+
|
56
|
+
enum gender: { 男性: 1, 女性: 2}
|
57
|
+
|
58
|
+
def self.ransackable_attributes(auth_object = nil)
|
59
|
+
%w(name idnumber workplace gender admin retired created_at)
|
60
|
+
end
|
61
|
+
|
62
|
+
def self.ransackable_assosiations(auth_object = nil)
|
63
|
+
[]
|
64
|
+
end
|
65
|
+
|
66
|
+
def self.csv_attributes
|
67
|
+
["idnumber", "name", "workplace", "email", "birth", "join_date", "gender", "retired", "admin", "root", "created_at", "updated_at", "HR"]
|
68
|
+
end
|
69
|
+
|
70
|
+
def self.generate_csv
|
71
|
+
CSV.generate(headers:true, encoding: Encoding::SJIS, row_sep: "\r\n", force_quotes: true) do |csv|
|
72
|
+
csv << csv_attributes
|
73
|
+
all.each do |user|
|
74
|
+
csv << csv_attributes.map{|attr| user.send(attr)}
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
end
|
80
|
+
```
|