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

Problem with new Route #2

Open
omarkhater-school opened this issue Sep 22, 2024 · 0 comments
Open

Problem with new Route #2

omarkhater-school opened this issue Sep 22, 2024 · 0 comments

Comments

@omarkhater-school
Copy link

omarkhater-school commented Sep 22, 2024

When I define the routes like that

get '/users', to: 'users#index'
get '/users/:id', to: 'users#show'
get '/users/new', to: 'users#new'

and tries to parse this route: GET /users/new

the parser returns:

Controller users
Action new
Params {}

but when I define it like:
resources :users

it returns:

The route GET /users/new parses to:

Controller users
Action show
Params {"id"=>"new"}

Maybe we need to modify recognize method in lib/route_recognizer to handle the reserved routes first?

def recognize(method, uri)
  # Handle reserved routes first
  return { 'controller' => 'users', 'action' => 'new' } if uri == '/users/new'
  return { 'controller' => 'users', 'action' => 'edit' } if uri == '/users/edit'
  
  # Then handle dynamic routes
  rack_request = RackRequest.new(method, uri)
  request = ActionDispatch::Request.new(rack_request.env)
  all_params = nil
  @routes.router.recognize(request) do |route, params|
    all_params = request.query_parameters.merge(params)
  end
  raise NoMatchingRouteError unless all_params
  all_params
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant