Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Chore: Consolidate multiple get routes into a single resources declaration for static pages #4855

Open
3 of 7 tasks
Tongxin-Sun opened this issue Nov 19, 2024 · 3 comments
Open
3 of 7 tasks
Assignees
Labels
Type: Chore Involves changes with no user-facing value, to the build process/internal tooling, refactors, etc.

Comments

@Tongxin-Sun
Copy link

Tongxin-Sun commented Nov 19, 2024

Checks

  • I have thoroughly read and understand The Odin Project Contributing Guide
  • The title of this issue follows the Chore: brief description of chore format, e.g. Chore: Lesson complete button does not update on click
  • Would you like to work on this issue?

Chore description

Currently, the routes for static pages like home, about, faq, team, contributing, support_us, terms_of_use, privacy-policy, and success_stories are declared individually using separate get statements in the routes.rb file. This approach can become cumbersome as the application grows and additional static pages are added. Refactoring these routes to use a single resources or scope declaration for the static_pages controller will streamline the routing configuration, improve readability, and make it easier to manage.

image

Acceptance criteria

  • Replace individual get routes for static pages (home, about, faq, team, contributing, support_us, terms_of_use, privacy-policy, and success_stories) with a single scope declaration for static_pages.
  • Ensure that all route paths and actions remain functional after refactoring.
  • Update all corresponding links and path helpers in the views to use the new resourceful routes (e.g., static_pages_path instead of individual page routes)
  • Test to confirm that all static pages render correctly and the paths are resolved as expected.

Additional Comments

No response

@Tongxin-Sun Tongxin-Sun added Status: Needs Review This issue/PR needs an initial or additional review Type: Chore Involves changes with no user-facing value, to the build process/internal tooling, refactors, etc. labels Nov 19, 2024
@github-project-automation github-project-automation bot moved this to 📋 Backlog / Ideas in Main Site Nov 19, 2024
@KevinMulhern
Copy link
Member

Thanks for the suggestion @Tongxin-Sun. How would we get individual paths, for example the faq path, using static_pages_path?

@Tongxin-Sun
Copy link
Author

Thanks for the suggestion @Tongxin-Sun. How would we get individual paths, for example the faq path, using static_pages_path?

Thank you for your response! If we organize all the routes under a single resources declaration like the following, the individual path names would change—for example, faq_path would become faq_static_pages_path.

resources :static_pages, only: [] do
  collection do
    get :home
    get :about
    get :faq
    get :team
    get :contributing
    get :support_us
    get :terms_of_use
    get 'privacy-policy', action: :privacy_policy
    get :success_stories
  end
end

While this method consolidates the routes, it requires updating all references to these paths in the codebase, which could involve significant effort depending on the scope of usage.

Alternatively, we could use a scope declaration, as shown below:

  scope controller: :static_pages do
    get 'home'
    get 'about'
    get 'faq'
    get 'team'
    get 'contributing'
    get 'support_us'
    get 'terms_of_use'
    get 'privacy-policy'
    get 'success_stories'
  end

This approach reduces redundancy by eliminating repeated mentions of static_pages, while preserving the current path names (e.g., faq_path remains unchanged). It strikes a balance between simplifying the routing logic and maintaining compatibility with the existing code.

Please let me know your thoughts. Would you prefer consolidating these routes under a resources or scope declaration for better organization? Or do you think it's better to retain the original get statements for simplicity?

@KevinMulhern
Copy link
Member

KevinMulhern commented Nov 25, 2024

Thanks for the great write up @Tongxin-Sun! I think the second approach using scope looks perfect 🤌

I've assigned it to you, let me know if you need anything from us!

@KevinMulhern KevinMulhern moved this from 📋 Backlog / Ideas to 🏗 In progress in Main Site Nov 25, 2024
@KevinMulhern KevinMulhern removed the Status: Needs Review This issue/PR needs an initial or additional review label Nov 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Chore Involves changes with no user-facing value, to the build process/internal tooling, refactors, etc.
Projects
Status: 🏗 In progress
Development

No branches or pull requests

2 participants