- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
# Work fine only on call with has_many association
def self.new_from_params options
new_rule = Rule.new
return nil if new_rule.project_id.nil?
rule = Rule.find_by_id options[:rule_id]
if rule.nil? or (new_rule.project.id != rule.project.id)
rule = Rule.new
end
new_rule.rule_id = options[:rule_id]
new_rule.users = (rule.users.to_a + options[:users].to_a).uniq
new_rule.statuses = (rule.statuses.to_a + options[:statuses].to_a).uniq
new_rule.tags = (rule.tags.to_a + options[:tags].to_a).uniq
new_rule.grouped_by = options[:grouped_by].presence || rule.grouped_by.presence
new_rule.sorted_by = options[:sorted_by].presence || rule.sorted_by.presence
new_rule.search = options[:search].presence || rule.search.presence
new_rule.period_start = options[:period_start].presence || rule.period_start.presence
new_rule.period_end = options[:period_end].presence || rule.period_end.presence
new_rule
end
airrussia 21.10.2011 22:05 # +3
guest 22.10.2011 00:17 # 0
Nook 20.11.2011 00:51 # 0
akostrikov 22.07.2013 11:21 # 0
bormand 22.07.2013 11:47 # 0
Эм. В руби можно вызывать методы у nil'а?