Lasha Amashukeli Lasha Amashukeli - 1 year ago 66
Ruby Question

Rails routes config thinks action method is an object id

I'm developing rails application and encountered such problem.

I have

, where I have these actions and routes defined:

Prefix Verb URI Pattern Controller#Action
movies GET /movies(.:format) movies#index
POST /movies(.:format) movies#create
new_movie GET /movies/new(.:format) movies#new
edit_movie GET /movies/:id/edit(.:format) movies#edit
movie GET /movies/:id(.:format) movies#show
PATCH /movies/:id(.:format) movies#update
PUT /movies/:id(.:format) movies#update
DELETE /movies/:id(.:format) movies#destroy
root GET / redirect(301, /movies)
movies_by_director GET /movies/by_director(.:format) movies#by_director

But when I try to go to
, rails think, that I'm navigating to
action with parameter
:id = by_director

What am I doing wrong?

Answer Source

Routes are matched in the order they are specified so make sure the route for "by_director" is defined above the resource routes for movies.

Something like this should do the trick:

get '/movies/by_director' => 'movies#by_director'
resources :movies
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download