Before I start off, I’m a Rails newbie, so if there is an obvious
solution to this problem, let me know!
I have a simple, blog-like Rails project. In the routes, I have a users
resource with a nested posts resource. Now, this is all fine and dandy
if everything is generated with Ruby.
Now, if I add an Ajax layer over this, things seem to complicate quite a
bit. Say, if I want to perform some kind of request using jQuery, I need
to be able to know the appropriate path to perform this request on (ex,
users/1/post/new), but this requires me to generate this path
dynamically in the Rails script. If I have couple hundred users, this
would mean that each one of these users would have to have these paths
dynamically generated. The issue is, this is not so good when it comes
to bandwidth, download times, and so forth.
And so I thought, why not split off the posts resource and NOT make it
nested? That way, I could have paths like ‘post/new’, and collect the
user information via the request. This makes the project extremely
unclean, however. It’s just not… pretty.
How can I handle this issue? What is the best way to approach it?