Skip to content

Commit 0bbcef7

Browse files
committed
fix tags
1 parent ef1f6df commit 0bbcef7

File tree

3 files changed

+7
-6
lines changed

3 files changed

+7
-6
lines changed

app/controllers/keys_controller.rb

+2-3
Original file line numberDiff line numberDiff line change
@@ -147,11 +147,10 @@ def create
147147
def update
148148
save_file if key_params[:file]
149149
respond_to do |format|
150-
151150
self.update_wishlist
152151

153-
if @key.update(params[:vault_key])
154-
@key.tags = Vault::Tag.create_from_string(key_params[:tags])
152+
if @key.update(key_params)
153+
@key.tags = key_params[:tags]
155154
format.html { redirect_to project_keys_path(@project), notice: t('notice.key.update.success') }
156155
else
157156
format.html { render action: 'edit' }

app/models/vault/key.rb

+4-2
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,12 @@ module Vault
44

55
class Vault::Key < ActiveRecord::Base
66
belongs_to :project
7-
has_and_belongs_to_many :tags
7+
has_and_belongs_to_many :tags, join_table: 'keys_vault_tags'
88

99
def tags=(tags_string)
10-
@tags = Vault::Tag.create_from_string(tags_string)
10+
tag_objects = Vault::Tag.create_from_string(tags_string)
11+
self.tags.clear
12+
self.tags << tag_objects
1113
end
1214

1315
def encrypt!

app/models/vault/tag.rb

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
module Vault
22
class Tag < ActiveRecord::Base
33
self.table_name = 'vault_tags'
4-
has_and_belongs_to_many :keys
4+
has_and_belongs_to_many :keys, join_table: 'keys_vault_tags'
55

66
validates :name, presence: true, uniqueness: true
77
validates :color, presence: true

0 commit comments

Comments
 (0)