help with rotues

in my cities controller I have

def for_provinceid   @cities = City.where("active = true && province_id = ?", params[:id]).sort_by{ |k| k['name'] }   respond_to do |format|     format.json { render :json => @cities }   end end

and in my zones controller I have

def for_cityid   @zones = Zone.where("active = true && city_id = ?", params[:id]).sort_by{ |k| k['name'] }   respond_to do |format|     format.json { render :json => @zones }   end end

how do i update my routes file that i can access the jason returned by these two actions.

YOu dont have to update route. It just returns the json. YOu can see it in the html.

must have to as doing http://localhost:3000//cities/for_provinceid/6 gives

Routing Error

No route matches "/cities/for_provinceid/6"

I think the question would be better put 'How do I update my routes file to allow me to invoke these actions' (unless I misunderstand). The Rails Guide on routing should point you in the right direction. If you still can't get it to work come back with what you have tried and what the result was. First, though I suggest reading up on RESTful routes to make sure that what you are doing is really what you want.


You have not set your routes properly. Take a look at Rails Routing from the Outside In — Ruby on Rails Guides. If you need more information, you can take a look at the link in my signature (articles 2, 3 and 5).


paste the result of rake commands

Have you add them to your routes.rb file (like any other action) ?


I don't think you are on the right path here. First of all, create a has_many and belongs to relationship. That will solve a lot if problems for you.