-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: Refactor code to use hidden_field instead of text_field for fo…
…rm_answer_ids Signed-off-by: Louis Kirkham <[email protected]>
- Loading branch information
1 parent
b97f0cc
commit 64bfdae
Showing
10 changed files
with
92 additions
and
96 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
28 changes: 13 additions & 15 deletions
28
app/controllers/admin/lieutenant_assignment_collections_controller.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,25 @@ | ||
class Admin::LieutenantAssignmentCollectionsController < Admin::BaseController | ||
def create | ||
@lieutenant_assignment_collection = LieutenantAssignmentCollection.new(create_params) | ||
authorize @lieutenant_assignment_collection, :create? | ||
@form = LieutenantAssignmentCollection.new(create_params) | ||
authorize @form, :create? | ||
|
||
@lieutenant_assignment_collection.subject = current_subject | ||
@form.subject = current_subject | ||
|
||
@lieutenant_assignment_collection.save | ||
|
||
respond_to do |format| | ||
format.html do | ||
flash[:notice] = @lieutenant_assignment_collection.notice_message | ||
flash[:error] = @lieutenant_assignment_collection.errors.full_messages.to_sentence | ||
redirect_back(fallback_location: root_path) | ||
end | ||
if @form.save | ||
# Change this - don't permit all params | ||
params.permit! | ||
redirect_to admin_form_answers_path(params: params), notice: @form.notice_message | ||
else | ||
# Ensure form_answer_ids is an array | ||
@form.form_answer_ids = @form.form_answer_ids.split(",") if @form.form_answer_ids.is_a?(String) | ||
render 'admin/form_answers/bulk_assign_lieutenants' | ||
end | ||
end | ||
|
||
private | ||
|
||
def create_params | ||
params | ||
.require(:lieutenant_assignment_collection) | ||
.permit(:form_answer_ids, | ||
:ceremonial_county_id) | ||
params.require(:lieutenant_assignment_collection) | ||
.permit(:form_answer_ids, :ceremonial_county_id, :year) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 7 additions & 2 deletions
9
app/views/admin/form_answers/bulk_assign_lieutenants.html.slim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH = -1 | ||
Nokogiri::Gumbo::DEFAULT_MAX_TREE_DEPTH = -1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,49 @@ | ||
class NominationsBulkActionForm | ||
attr_reader :params | ||
attr_reader :params, :errors | ||
include Rails.application.routes.url_helpers | ||
|
||
def initialize(params) | ||
@params = params | ||
end | ||
|
||
def kind | ||
@kind ||= if params[:bulk_assign_lieutenants] | ||
"lieutenants" | ||
elsif params[:bulk_assign_assessors] | ||
"assessors" | ||
elsif params[:bulk_assign_eligibility] | ||
"eligibility" | ||
end | ||
@errors = ActiveModel::Errors.new(self) | ||
@kind = determine_kind | ||
end | ||
|
||
def valid? | ||
if !params[:bulk_action].present? | ||
errors.add(:bulk_base, "You must select at least one group from the list below before clicking a bulk action button.") | ||
|
||
@errors.add(:bulk_base, "You must select at least one group from the list below before clicking a bulk action button.") | ||
return false | ||
end | ||
|
||
case kind | ||
when "lieutenants" | ||
params[:bulk_action].present? | ||
when "assessors" | ||
params[:bulk_action].present? | ||
when "eligibility" | ||
case @kind | ||
when "lieutenants", "assessors", "eligibility" | ||
params[:bulk_action].present? | ||
else | ||
@errors.add(:bulk_base, "Invalid bulk action type.") | ||
false | ||
end | ||
end | ||
|
||
def redirect_url | ||
case kind | ||
case @kind | ||
when "lieutenants" | ||
bulk_assign_lieutenants_admin_form_answers_path(params: params) | ||
when "assessors" | ||
bulk_assign_assessors_admin_form_answers_path(params: params) | ||
bulk_assign_assessors_admin_form_answers_path(params: permitted_params) | ||
when "eligibility" | ||
bulk_assign_eligibility_admin_form_answers_path(params: params) | ||
bulk_assign_eligibility_admin_form_answers_path(params: permitted_params) | ||
else | ||
# Handle invalid kind | ||
raise "Invalid bulk action type." | ||
end | ||
end | ||
|
||
def determine_kind | ||
if params[:bulk_assign_lieutenants] | ||
"lieutenants" | ||
elsif params[:bulk_assign_assessors] | ||
"assessors" | ||
elsif params[:bulk_assign_eligibility] | ||
"eligibility" | ||
end | ||
end | ||
end |