I created a new action called “asked”. asked.haml is in views/questions as it should be. I’ve also added
def asked
respond_to do |format|
format.html
format.xml { render :xml => @questions }
end
end
to the Questions controller for this action.
My problem is that when I got to the url http://localhost:3000/questions/asked, I get this error:
ActiveRecord::RecordNotFound in QuestionsController#show
Couldn't find Question with ID=asked
So, I Googled this and found out that I needed to change the way I route things.
I tried: map.connect ':controller/asked', :action => 'asked' and map.resources :questions, :collection => {:asked => :get}, but to no avail.
Obviously I don’t fully understand how Rails mapping works, but if someone would let me know what’s going on, I’d really appreciate it!
Rails routing works by picking the first route that matches the requested URL.
From your description it seems that you put your
map.connectstatements to the bottom of yourroutes.rb. You should place it beforemap.resources :questions, since otherwise the URL/questions/askedis matched bymap.resourcesas ashowaction.