RESTful routes?

15 views
Skip to first unread message

Lena Herrmann

unread,
Oct 14, 2009, 9:49:42 AM10/14/09
to Sammy.js
Hi!

I'm working on an app with Sammy / Couchapp / CouchDB. At the moment
you can create and view notes - delete and update are next (how
fancy).

I want to do the routes RESTful, so my ideal routes look like this:

index: get('#/notes')
show: get('#/notes/:id')
new: get('#/notes/new')
create: post('#/notes')
edit: get('#/notes/:id/edit')
update: put('#/notes/:id')
delete: delete('#/notes/:id')

(Yes, I've been working with Rails so far).

Are these names possible with Sammy routing? Because I can't seem to
have both the routes get('#/notes/:id') and get('#/notes'). It works
fine with get('#/note/:id') and get('#/notes'). But that's not really
nice.

Any ideas?

Lena

Aaron Quint

unread,
Oct 14, 2009, 10:21:28 AM10/14/09
to sam...@googlegroups.com
Hey Lena

That should all work in Sammy.js with one exception: delete().
Unfortunately delete is a keyword in Javascript so you cant have
delete() methods. The easy workaround for this is:

route('delete', '#/notes/:id', function() {});

Thats strange about the plural/singular routes. What version of Sammy
are you using? If you could share some code, I could probably help
debug better. As of 0.3 routes are added and looked up in the order
you add them, where before they were sorted by length.

--AQ

Aaron Quint
http://www.quirkey.com

Lena Herrmann

unread,
Oct 14, 2009, 11:13:11 AM10/14/09
to sam...@googlegroups.com
Hrrgh,

upgrade to Sammy 0.3.0 helped, I was using an older version. It's
working now. Thank you anyway!!

Lena



Aaron Quint schrieb:
Reply all
Reply to author
Forward
0 new messages