-
Notifications
You must be signed in to change notification settings - Fork 28
/
table_memos_controller.rb
43 lines (36 loc) · 1.25 KB
/
table_memos_controller.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
class TableMemosController < ApplicationController
permits :description
before_action :redirect_named_path, only: :show
def show(database_name, schema_name, name)
@table_memo = TableMemo.
includes(column_memos: :logs).
joins(:schema_memo).
merge(SchemaMemo.where(name: schema_name).joins(:database_memo).merge(DatabaseMemo.where(name: database_name))).
where(name:).
take!
@view_meta_data = @table_memo.view_meta_data
end
def edit(id)
@table_memo = TableMemo.find(id)
end
def update(id, table_memo)
@table_memo = TableMemo.find(id)
@table_memo.assign_attributes(table_memo)
if @table_memo.changed?
@table_memo.build_log(current_user.id)
@table_memo.save!
end
redirect_to database_schema_table_path(@table_memo.database_memo.name, @table_memo.schema_memo.name, @table_memo.name)
end
def destroy(id)
table_memo = TableMemo.find(id)
table_memo.destroy!
redirect_to database_memo_path(table_memo.database_memo.name)
end
private
def redirect_named_path(id = nil)
return unless id =~ /\A\d+\z/
table_memo = TableMemo.find(id)
redirect_to database_schema_table_path(table_memo.database_memo.name, table_memo.schema_memo.name, table_memo.name)
end
end