Created
December 11, 2010 09:05
-
-
Save durus/737274 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I am having problem with routes in Ruby and hope that someone can help me. I have problem understanding how routes works. My code is generating the following url: | |
http://localhost:3000/getnotes/category/?id=1 and I am getting this error: | |
Routing Error | |
No route matches "/getnotes/category" | |
How can I get it to work? | |
this url works for some reason but I can't use it since I later need encode my data before sending it. | |
http://localhost:3000/getnotes/category/1.js | |
Jquery code to get the notes | |
function getWithAjax(url, data) { | |
$.ajax({ | |
beforeSend: function(xhr) {xhr.setRequestHeader("Accept", "text/javascript")}, | |
url: url, | |
data: data | |
}); | |
}; | |
function getNotesByCategory(id){ | |
getWithAjax("/getnotes/category/",{ id: id}); | |
}; | |
I have a route | |
get '/getnotes/category/:id', :to => "notes#category", :as => 'notes' | |
my rake routes shows | |
notes GET /getnotes/category/:id(.:format) {:controller=>"notes", :action=>"category"} | |
My Action | |
def category | |
category = Category.find(params[:id]) | |
json = Array.new | |
@notes = category.notes | |
respond_to do |format| | |
format.json { render :json => category.notes } | |
format.js | |
end | |
end | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment