diff --git a/app/controllers/categories_controller.rb b/app/controllers/categories_controller.rb index b4df5fe62..7fc246c39 100644 --- a/app/controllers/categories_controller.rb +++ b/app/controllers/categories_controller.rb @@ -42,7 +42,7 @@ def create authorize! @category if @category.save - redirect_to categories_path, notice: "Category was successfully created." + redirect_to @category, notice: "Category was successfully created." else set_form_variables render :new, status: :unprocessable_content @@ -53,7 +53,7 @@ def update authorize! @category respond_to do |format| if @category.update(category_params) - format.html { redirect_to categories_path, notice: "Category was successfully updated.", status: :see_other } + format.html { redirect_to @category, notice: "Category was successfully updated.", status: :see_other } format.json { head :ok } else format.html do diff --git a/app/controllers/category_types_controller.rb b/app/controllers/category_types_controller.rb index 09024563b..aec98eac2 100644 --- a/app/controllers/category_types_controller.rb +++ b/app/controllers/category_types_controller.rb @@ -29,7 +29,7 @@ def create authorize! @category_type if @category_type.save - redirect_to category_types_path, notice: "Category type was successfully created." + redirect_to @category_type, notice: "Category type was successfully created." else @category_type = @category_type.decorate render :new, status: :unprocessable_content @@ -39,7 +39,7 @@ def create def update authorize! @category_type if @category_type.update(category_type_params) - redirect_to category_types_path, notice: "Category type was successfully updated.", status: :see_other + redirect_to @category_type, notice: "Category type was successfully updated.", status: :see_other else @category_type = @category_type.decorate render :edit, status: :unprocessable_content diff --git a/app/controllers/faqs_controller.rb b/app/controllers/faqs_controller.rb index 19086a22e..06d292728 100644 --- a/app/controllers/faqs_controller.rb +++ b/app/controllers/faqs_controller.rb @@ -30,7 +30,7 @@ def create authorize! @faq if @faq.save - redirect_to faqs_path, notice: "FAQ was successfully created." + redirect_to @faq, notice: "FAQ was successfully created." else set_form_variables render :new, status: :unprocessable_content @@ -42,7 +42,7 @@ def update notice = "FAQ was successfully updated." flash.now[:notice] = notice if @faq.update(faq_params) - redirect_to faqs_path, notice: notice, status: :see_other + redirect_to @faq, notice: notice, status: :see_other else set_form_variables render :edit, status: :unprocessable_content diff --git a/app/controllers/organization_statuses_controller.rb b/app/controllers/organization_statuses_controller.rb index 4ab70f00b..9b96b3f4a 100644 --- a/app/controllers/organization_statuses_controller.rb +++ b/app/controllers/organization_statuses_controller.rb @@ -31,7 +31,7 @@ def create authorize! @organization_status if @organization_status.save - redirect_to organization_statuses_path, notice: "Organization status was successfully created." + redirect_to @organization_status, notice: "Organization status was successfully created." else @organization_status = OrganizationStatus.new.decorate set_form_variables @@ -42,7 +42,7 @@ def create def update authorize! @organization_status if @organization_status.update(organization_status_params) - redirect_to organization_statuses_path, notice: "Organization status was successfully updated.", status: :see_other + redirect_to @organization_status, notice: "Organization status was successfully updated.", status: :see_other else @organization_status = OrganizationStatus.new.decorate set_form_variables diff --git a/app/controllers/sectors_controller.rb b/app/controllers/sectors_controller.rb index d0afd0399..ece19f646 100644 --- a/app/controllers/sectors_controller.rb +++ b/app/controllers/sectors_controller.rb @@ -32,7 +32,7 @@ def create authorize! @sector if @sector.save - redirect_to sectors_path, notice: "Sector was successfully created." + redirect_to @sector, notice: "Sector was successfully created." else set_form_variables render :new, status: :unprocessable_content @@ -42,7 +42,7 @@ def create def update authorize! @sector if @sector.update(sector_params) - redirect_to sectors_path, notice: "Sector was successfully updated.", status: :see_other + redirect_to @sector, notice: "Sector was successfully updated.", status: :see_other else set_form_variables render :edit, status: :unprocessable_content diff --git a/app/controllers/windows_types_controller.rb b/app/controllers/windows_types_controller.rb index 01bf4228b..b0df30cde 100644 --- a/app/controllers/windows_types_controller.rb +++ b/app/controllers/windows_types_controller.rb @@ -33,7 +33,7 @@ def create @windows_type.categories = Category.where(id: selected_ids) if @windows_type.save - redirect_to windows_types_path, notice: "Windows type was successfully created." + redirect_to @windows_type, notice: "Windows type was successfully created." else set_form_variables render :new, status: :unprocessable_content @@ -47,7 +47,7 @@ def update @windows_type.categories = Category.where(id: selected_ids) if @windows_type.update(windows_type_params) - redirect_to windows_types_path, notice: "Windows type was successfully updated.", status: :see_other + redirect_to @windows_type, notice: "Windows type was successfully updated.", status: :see_other else set_form_variables render :edit, status: :unprocessable_content diff --git a/lib/templates/rails/scaffold_controller/controller.rb.tt b/lib/templates/rails/scaffold_controller/controller.rb.tt index a8bda3244..bab2cfbde 100644 --- a/lib/templates/rails/scaffold_controller/controller.rb.tt +++ b/lib/templates/rails/scaffold_controller/controller.rb.tt @@ -28,7 +28,7 @@ class <%= controller_class_name %>Controller < ApplicationController @<%= singular_table_name %> = <%= orm_class.build(class_name, "#{singular_table_name}_params") %> if @<%= orm_instance.save %> - redirect_to <%= index_helper %>_path, notice: "<%= human_name %> was successfully created." + redirect_to @<%= singular_table_name %>, notice: "<%= human_name %> was successfully created." else @<%= singular_table_name %> = <%= orm_class.build(class_name) %>.decorate set_form_variables @@ -38,7 +38,7 @@ class <%= controller_class_name %>Controller < ApplicationController def update if @<%= orm_instance.update("#{singular_table_name}_params") %> - redirect_to <%= index_helper %>_path, notice: "<%= human_name %> was successfully updated.", status: :see_other + redirect_to @<%= singular_table_name %>, notice: "<%= human_name %> was successfully updated.", status: :see_other else @<%= singular_table_name %> = <%= orm_class.build(class_name) %>.decorate set_form_variables diff --git a/spec/requests/categories_spec.rb b/spec/requests/categories_spec.rb index b10f6be53..6de2dcb2f 100644 --- a/spec/requests/categories_spec.rb +++ b/spec/requests/categories_spec.rb @@ -67,7 +67,7 @@ post categories_path, params: { category: valid_attributes } }.to change(Category, :count).by(1) - expect(response).to redirect_to(categories_path) + expect(response).to redirect_to(category_path(Category.last)) end end diff --git a/spec/requests/faqs_spec.rb b/spec/requests/faqs_spec.rb index d3e59f2bf..5cc465fd8 100644 --- a/spec/requests/faqs_spec.rb +++ b/spec/requests/faqs_spec.rb @@ -138,9 +138,9 @@ }.to change(Faq, :count).by(1) end - it "redirects to the faqs index" do + it "redirects to the created faq" do post faqs_url, params: { faq: valid_attributes } - expect(response).to redirect_to(faqs_url) + expect(response).to redirect_to(faq_url(Faq.last)) end end @@ -176,9 +176,9 @@ expect(faq.answer).to eq("Updated answer text.") end - it "redirects to the faqs index" do + it "redirects to the faq" do patch faq_url(faq), params: { faq: new_attributes } - expect(response).to redirect_to(faqs_url) + expect(response).to redirect_to(faq_url(faq)) end end diff --git a/spec/requests/organization_statuses_spec.rb b/spec/requests/organization_statuses_spec.rb index 9a48753c9..868e72e6e 100644 --- a/spec/requests/organization_statuses_spec.rb +++ b/spec/requests/organization_statuses_spec.rb @@ -39,7 +39,7 @@ post organization_statuses_path, params: valid_params }.to change(OrganizationStatus, :count).by(1) - expect(response).to redirect_to(organization_statuses_path) + expect(response).to redirect_to(organization_status_path(OrganizationStatus.last)) end it "rejects invalid create" do @@ -51,7 +51,7 @@ patch organization_status_path(status), params: { organization_status: { name: "Updated" } } - expect(response).to redirect_to(organization_statuses_path) + expect(response).to redirect_to(organization_status_path(status)) expect(status.reload.name).to eq("Updated") end diff --git a/spec/requests/sectors_spec.rb b/spec/requests/sectors_spec.rb index ff48bcaea..1b9e96b0e 100644 --- a/spec/requests/sectors_spec.rb +++ b/spec/requests/sectors_spec.rb @@ -60,9 +60,9 @@ }.to change(Sector, :count).by(1) end - it "redirects to sectors index" do + it "redirects to the created sector" do post sectors_url, params: { sector: valid_attributes } - expect(response).to redirect_to(sectors_url) + expect(response).to redirect_to(sector_url(Sector.last)) end end @@ -95,11 +95,11 @@ skip("Add assertions for updated state") end - it "redirects to the sectors index" do + it "redirects to the sector" do sector = Sector.create! valid_attributes patch sector_url(sector), params: { sector: new_attributes } sector.reload - expect(response).to redirect_to(sectors_url) + expect(response).to redirect_to(sector_url(sector)) end end diff --git a/spec/requests/windows_types_spec.rb b/spec/requests/windows_types_spec.rb index 5b17d99f7..23ac389d7 100644 --- a/spec/requests/windows_types_spec.rb +++ b/spec/requests/windows_types_spec.rb @@ -62,7 +62,7 @@ it "redirects to the created windows_type" do post windows_types_url, params: { windows_type: valid_attributes } - expect(response).to redirect_to(windows_types_url) + expect(response).to redirect_to(windows_type_url(WindowsType.last)) end end @@ -96,7 +96,7 @@ it "redirects to the windows_type" do windows_type = WindowsType.create!(valid_attributes) patch windows_type_url(windows_type), params: { windows_type: new_attributes } - expect(response).to redirect_to(windows_types_url) + expect(response).to redirect_to(windows_type_url(windows_type)) end end