views:

162

answers:

1

Hello, this is my first post on this website, but I'm all the time getting answers for my questions here, through other users, so thank you very much.

Well, actually I'm creating a web application, specifically on rails. All the models structure were built and now I was pretending to start to build the controllers and routing. So, I have a couple of questions regarding the proper way to build these routes.

First thing I did was search through some nice applications and check how they've built their routing structure. Twitter have nice ones,I noticed that they created a session for each login and all the following routing is based on the root level so the user/account is inherited to it. (i.e : http://twitter.com/status/update)


Well, the main structure of my app is:

account/blogs/#{id}/pages/#{id}...and so on...

Actually the account owner can be a developer or just a simple user while the developer have more features to deal with. But it's the same model just with the attr developer:Boolean setting its permissions.

Account{:id, :username, :email, :developer}

So my question is: What's the best way to create a some nice routes to create this account if I have two different types user/developer?

I was thinking if this would be correct:

/account/create for simple users

/account/create?type=developer for developers

Can I use extra parameters declared on the post request, or at least on the GET to display the form?


And at the same time I checked some guides and I read about some RESTful routing where we can have something like:

accounts/1/blogs/1/pages/1

but for example, the stackoverflow.com wesite acts this way:

/users/165750/ludicco and /users/edit/165750

So it's using a little bit different order. is this a proper formatted way to do it?


Sorry, but I'm kinda lost, so I don't know how to proceed on this field yet. Any help or tips about it would be much appreciated.

Thanks in advance

+1  A: 

Unfortunately for someone getting started, there are no laws to provide guidance. You've probably done about as much as you can by reading some recommendations. Personally, if I'm going for restful, I'd avoid sessions as much as possible, and put information in the URLs.

create: Since you are posting the name/email/etc. data, I would post the developer flag also. I'd need to know more about your form to say whether the developer parameter is a good idea; it really doesn't matter much in this case. I'd say if it's a flag in your signup-form view, the parameter is good, and if they are truly different pages, a different base url would make more sense.

regular pages: Your accounts/1/blogs/1/pages/1 is very unambiguous for humans and should be easy on machines as well. Stackoverflow uses a more compact notation, with some redundant information to help out humans and search engines. Use whichever you like better.

Justin Love
Well, this was a very good help Justin, thanks for that. I'll keep reading more about REST and so where I can get. Originally I read this article wonderfullyflawed.com/2009/07/… And it made me think on a possible future use as an API, so I got some ideas from there. as it was very helpful to me. This a completely new world for me but I really like it, since it's not difficult, I'm just wondering to make it right, but as you said, for starters it's a kind of ongoing thing and I can keep modifying my code later. Thanks a lot Justin
ludicco