Skip to content

Instantly share code, notes, and snippets.

@pixeltrix
Created January 27, 2025 07:52
Show Gist options
  • Save pixeltrix/31cf0658dd984cc98a2ab38463452cf9 to your computer and use it in GitHub Desktop.
Save pixeltrix/31cf0658dd984cc98a2ab38463452cf9 to your computer and use it in GitHub Desktop.
Deepseek responses when asked to build routes file

Generate a Ruby on Rails routes file that namespaces a resource called 'Page' under the path '/admin' and restrict it to just the index, edit and update actions.

Certainly! Below is an example of how you can define a routes.rb file in a Ruby on Rails application to namespace the Page resource under the /admin path and restrict it to only the index, edit, and update actions:

# config/routes.rb

Rails.application.routes.draw do
  namespace :admin do
    resources :pages, only: [:index, :edit, :update]
  end

  # Other routes can go here
end

Explanation:

  • namespace :admin: This creates a namespace for the Page resource under the /admin path. This means that all routes for Page will be prefixed with /admin.
  • resources :pages, only: [:index, :edit, :update]: This defines the Page resource but restricts it to only the index, edit, and update actions. The only: option is used to specify which actions should be routed.

Resulting Routes:

Running rails routes in the terminal will generate the following routes:

Prefix Verb   URI Pattern                   Controller#Action
admin_pages GET    /admin/pages(.:format)          admin/pages#index
edit_admin_page GET    /admin/pages/:id/edit(.:format) admin/pages#edit
admin_page PATCH  /admin/pages/:id(.:format)      admin/pages#update
             PUT    /admin/pages/:id(.:format)      admin/pages#update

These routes will allow you to:

  • List all pages (GET /admin/pages)
  • Edit a specific page (GET /admin/pages/:id/edit)
  • Update a specific page (PATCH /admin/pages/:id or PUT /admin/pages/:id)

Let me know if you need further assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment