Skip to content

Commit b2eaac4

Browse files
committed
Replace condition_exists w/ condition.present?
- #3497 introduces `<% condition ||= nil %>` on line 6. - This refactor replaces the usage of `condition_exists` with `condition.present?` - `app/views/org_admin/conditions/_container.html.erb` appears to be the only `app/views/org_admin/conditions/_form.html.erb` that passes the `locals : { condition` variable. The `<% condition ||= nil %>` code on line 6 should be sufficient for performing this check. - Additionally, if `condition == nil` and `condition_exists == true` ever occurred, then we would encounter `NoMethodError` exceptions on lines 13 and 27.
1 parent c7abc11 commit b2eaac4

File tree

1 file changed

+3
-4
lines changed

1 file changed

+3
-4
lines changed

app/views/org_admin/conditions/_form.html.erb

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,8 @@
1010
action_type_arr = [["removes", :remove], ["adds notification", :add_webhook]]
1111
name_start = "conditions[#{condition_no.to_s}]"
1212
remove_question_collection = later_question_list(question)
13-
condition_exists = local_assigns.has_key? :condition
14-
type_default = condition_exists ? (condition[:action_type] == "remove" ? :remove : :add_webhook) : :remove
15-
remove_question_group = condition_exists ?
13+
type_default = condition.present? ? (condition[:action_type] == "remove" ? :remove : :add_webhook) : :remove
14+
remove_question_group = condition.present? ?
1615
grouped_options_for_select(remove_question_collection, condition[:remove_question_id]) :
1716
grouped_options_for_select(remove_question_collection)
1817
view_email_content_info = _("Hover over the email address to view email content. To change email details you need to remove and add the condition again.")
@@ -25,7 +24,7 @@
2524
<div class="col-md-9 pe-2">
2625
<div class="form-label bold"><%= _('Option') %></div>
2726
<%= select_tag(:question_option, options_from_collection_for_select(question.question_options.sort_by(&:number), "id", "text",
28-
condition_exists ? condition[:question_option_id] : question.question_options.sort_by(&:number)[0]), {class: 'form-select regular', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3', name: name_start + "[question_option][]"}) %>
27+
condition.present? ? condition[:question_option_id] : question.question_options.sort_by(&:number)[0]), {class: 'form-select regular', 'data-bs-style': 'dropdown-toggle bg-white px-4 py-3', name: name_start + "[question_option][]"}) %>
2928
</div>
3029
<div class="col-md-3 pe-2">
3130
<div class="form-label bold"><%= _('Action') %></div>

0 commit comments

Comments
 (0)