Skip to content

Commit 58f6b76

Browse files
authored
fix issue with one-click plan creation (#2581)
1 parent 92b1198 commit 58f6b76

2 files changed

Lines changed: 18 additions & 13 deletions

File tree

app/controllers/plans_controller.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -91,15 +91,15 @@ def create
9191
# plan.funder which forces the hidden id hash to be :id
9292
# so we need to convert it to :org_id so it works with the
9393
# OrgSelectable and OrgSelection services
94-
if params[:org][:id].present?
95-
attrs = params[:org]
96-
attrs[:org_id] = attrs[:id]
97-
@plan.org = org_from_params(params_in: attrs, allow_create: false)
94+
org_hash = plan_params[:org] || params[:org]
95+
if org_hash[:id].present?
96+
org_hash[:org_id] = org_hash[:id]
97+
@plan.org = org_from_params(params_in: org_hash, allow_create: false)
9898
end
99-
if params[:funder][:id].present?
100-
attrs = params[:funder]
101-
attrs[:org_id] = attrs[:id]
102-
@plan.funder = org_from_params(params_in: attrs, allow_create: false)
99+
funder_hash = plan_params[:funder] || params[:funder]
100+
if funder_hash[:id].present?
101+
funder_hash[:org_id] = funder_hash[:id]
102+
@plan.funder = org_from_params(params_in: funder_hash, allow_create: false)
103103
end
104104

105105
if @plan.save

app/helpers/template_helper.rb

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,18 @@ def links_to_a_elements(links, separator = ", ")
3939
# @param text [String] text for the link
4040
# @param id [String] id for the link element
4141
def direct_link(template, hidden = false, text = nil, id = nil)
42-
params = { org_id: template.org.id, funder_id: '-1', template_id: template.id }
43-
cls = text.nil? ? 'direct-link' : 'direct-link btn btn-default'
44-
style = hidden ? 'display: none' : ''
42+
params = {
43+
org: { id: current_user&.org&.id },
44+
funder: { id: template.org&.id },
45+
template_id: template.id
46+
}
47+
cls = text.nil? ? "direct-link" : "direct-link btn btn-default"
48+
style = hidden ? "display: none" : ""
4549

46-
link_to(plans_url(plan: params), method: :post, title: _('Create plan'), class: cls, id: id, style: style) do
50+
link_to(plans_url(plan: params), method: :post, title: _("Create plan"),
51+
class: cls, id: id, style: style) do
4752
if text.nil?
48-
'<span class="fa fa-plus-square"></span>'.html_safe
53+
"<span class=\"fa fa-plus-square\"></span>".html_safe
4954
else
5055
text.html_safe
5156
end

0 commit comments

Comments
 (0)