From de27c7a56cc1e5e59b439268dd900258b67990b6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Javi=20Mart=C3=ADn?= Date: Wed, 2 Jun 2021 16:10:48 +0200 Subject: [PATCH] Use local variables in group and heading partials We usually prefer local variables over instance variables in partials. This way we'll be able to call the partial from views or components where the instance variable isn't available. And since we're using the `path` variable to configure the URL, we don't have to specify extra variables like `@budget` or the namespace `:admin` in `form_for`, since Rails only uses those variables to set the URL. --- app/views/admin/budget_groups/_form.html.erb | 10 +++++----- app/views/admin/budget_groups/edit.html.erb | 2 +- app/views/admin/budget_groups/new.html.erb | 2 +- app/views/admin/budget_headings/_form.html.erb | 8 ++++---- app/views/admin/budget_headings/edit.html.erb | 2 +- app/views/admin/budget_headings/new.html.erb | 2 +- 6 files changed, 13 insertions(+), 13 deletions(-) diff --git a/app/views/admin/budget_groups/_form.html.erb b/app/views/admin/budget_groups/_form.html.erb index ac89d033d..b50378063 100644 --- a/app/views/admin/budget_groups/_form.html.erb +++ b/app/views/admin/budget_groups/_form.html.erb @@ -1,8 +1,8 @@ -<%= render "shared/globalize_locales", resource: @group %> +<%= render "shared/globalize_locales", resource: group %> -<%= translatable_form_for [:admin, @budget, @group], url: path do |f| %> +<%= translatable_form_for group, url: path do |f| %> - <%= render "shared/errors", resource: @group %> + <%= render "shared/errors", resource: group %>
<%= f.translatable_fields do |translations_form| %> @@ -12,11 +12,11 @@ <% end %>
- <% if @group.persisted? %> + <% if group.persisted? %>
<%= f.select :max_votable_headings, - (1..@group.headings.count), + (1..group.headings.count), hint: t("admin.budget_groups.form.max_votable_headings_info") %>
diff --git a/app/views/admin/budget_groups/edit.html.erb b/app/views/admin/budget_groups/edit.html.erb index 0730a4206..c43b26d38 100644 --- a/app/views/admin/budget_groups/edit.html.erb +++ b/app/views/admin/budget_groups/edit.html.erb @@ -1,3 +1,3 @@ <%= render "header", action: "edit" %> -<%= render "form", path: admin_budget_group_path(@budget, @group), action: "submit" %> +<%= render "form", group: @group, path: admin_budget_group_path(@budget, @group), action: "submit" %> diff --git a/app/views/admin/budget_groups/new.html.erb b/app/views/admin/budget_groups/new.html.erb index 461427d44..098ac5446 100644 --- a/app/views/admin/budget_groups/new.html.erb +++ b/app/views/admin/budget_groups/new.html.erb @@ -1,3 +1,3 @@ <%= render "header", action: "create" %> -<%= render "form", path: admin_budget_groups_path(@budget), action: "create" %> +<%= render "form", group: @group, path: admin_budget_groups_path(@budget), action: "create" %> diff --git a/app/views/admin/budget_headings/_form.html.erb b/app/views/admin/budget_headings/_form.html.erb index 06eae3926..2ac0d2c66 100644 --- a/app/views/admin/budget_headings/_form.html.erb +++ b/app/views/admin/budget_headings/_form.html.erb @@ -1,8 +1,8 @@ -<%= render "shared/globalize_locales", resource: @heading %> +<%= render "shared/globalize_locales", resource: heading %> -<%= translatable_form_for [:admin, @budget, @group, @heading], url: path do |f| %> +<%= translatable_form_for heading, url: path do |f| %> - <%= render "shared/errors", resource: @heading %> + <%= render "shared/errors", resource: heading %>
<%= f.translatable_fields do |translations_form| %> @@ -16,7 +16,7 @@
<%= f.text_field :price, maxlength: 8 %> - <% if @heading.budget.approval_voting? %> + <% if heading.budget.approval_voting? %> <%= f.number_field :max_ballot_lines, hint: t("admin.budget_headings.form.max_ballot_lines_info") %> diff --git a/app/views/admin/budget_headings/edit.html.erb b/app/views/admin/budget_headings/edit.html.erb index 124d07510..2102d8e3c 100644 --- a/app/views/admin/budget_headings/edit.html.erb +++ b/app/views/admin/budget_headings/edit.html.erb @@ -1,3 +1,3 @@ <%= render "header", action: "edit" %> -<%= render "form", path: admin_budget_group_heading_path(@budget, @group, @heading), action: "submit" %> +<%= render "form", heading: @heading, path: admin_budget_group_heading_path(@budget, @group, @heading), action: "submit" %> diff --git a/app/views/admin/budget_headings/new.html.erb b/app/views/admin/budget_headings/new.html.erb index 0566a5a5e..3e1810fbc 100644 --- a/app/views/admin/budget_headings/new.html.erb +++ b/app/views/admin/budget_headings/new.html.erb @@ -1,3 +1,3 @@ <%= render "header", action: "create" %> -<%= render "form", path: admin_budget_group_headings_path(@budget, @group), action: "create" %> +<%= render "form", heading: @heading, path: admin_budget_group_headings_path(@budget, @group), action: "create" %>