わかりやすく書けるだろうか。
railsのviewでログの出力を出し分けする以下のメソッドがあります。
user _profile _log
use _favorite _log
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
|
def genarate_link_path(log_type,log)
case log_type
when :warm
"http://" + config[:host] + "/info/" + "warm"
when :error
"http://" + config[:host] + "/info/" + "error"
end
end
def user_profile_log(log)
disp_path = genarate_link_path(:warn,log)
case log.operation_type
when "insert"
change_value = log.inspect + "ログを新規登録しました。"
when "update"
change_value = log.inspect + "ログを更新しました。"
else
"解析に失敗しました"
end
return link_to( change_value , disp_path )
end
def use_favorite_log(log)
disp_path = genarate_link_path(:warn,log)
case log.operation_type
when "insert"
change_value = log.name + "をお気に入りに追加しました。"
when "update"
change_value = log.name + "を更新しました。"
else
"解析に失敗しました"
end
return link_to( change_value , disp_path )
end
|
DRYじゃないですよね。
それぞれのメソッドでは
disp _path = genarate _link _path(:warn,log)
return link _to( change _value , disp _path )
が二つのメソッドでかぶっております。