I want to look up an object from the database using a GET with a parameter other than :id using a generated controller.
Currently when I GET /parties/8.json
{"id":8,"Name":"testname","Date":"5 July, 2015","Location":"testlocation","Requirements":null,"Password":"","URL":"WMKQUBBC","Token":"testtoken","created_at":"2015-07-05T23:45:22.474Z","updated_at":"2015-07-05T23:45:30.293Z"}
I want to be able to GET /parties/WMKQUBBC.json and get the same response, but it currently looks up only by :id.
I tried adding it in routes.rb
get 'parties/:URL' => 'parties#show'
resources :parties
to work with my parties_controller.rb
# GET /parties/1
# GET /parties/1.json
def show
@party = Party.find_by_URL(:URL)
format.html { redirect_to @party }
format.json { render :show, location: @party }
end
but I still get a ActiveRecord::RecordNotFound exception, it seems like the action is defaulting to the standard Rails behavior for parties#show and it isn't even hitting my Party.find_by_URL(:URL) code.
Any ideas?