note: the gist of the question is in the first update below
I'm maintaing a rails project and I noticed that if I do a GET "/request/past_list"
I'm routed to RequestController#show
in routes.rb
I got:
get '/request/past_list', to: 'request#past_list'
get '/request/:id', to: 'request#show'
and running rake routes
I get (predictably):
request_past_list GET /request/past_list(.:format) request#past_list
GET /request/:id(.:format) request#show
So i'm wondering why is rails thinking that my past_list
string in the url is actually an :id
?
for now this is the workaround I implemented:
def show
if ((params[:id]).is_a? String and (params[:id].eql? "past_list"))
past_list
else
..
but i'm already having trouble sleeping at night because of it.. i'm hoping to know what's really going on to rest my conscience
p.s. this is what the network request looks like on chrome dev tools, just in case if there is some detail that may raise a red flag:
update: i noticed a difference between how the request is interpreted in my current code:
Started GET "/request/past_list" for 127.0.0.1 at 2014-02-13 15:41:14 +0200
Processing by RequestController#show as JSON
and the old working one i dug up from git history:
Started GET "/request/past_list" for 127.0.0.1 at 2014-02-13 15:43:40 +0200
Processing by RequestController#past_list as */*
the thing is the old working code has the exact same routes.rb file.. no changes there!
so i guess it's a difference between interpreting the request as JSON
and as */*
..
second update:
here are two questions related to this */*
business:
When do Rails controllers render as JS, HTML, or 'q'?
and
Rails 3 Processing by */*