Weird Problem with Post Submit Route


#1

I am currently reading through Discover Meteor, while simultaneously building the Microscope app from the book (i.e. typing the code myself - not copying & pasting or downloading it using Git).

Today I updated Meteor to version 1.1.0.3, and I discovered in my version of the code for that my route for creating new posts, ‘/posts/new’ was broken. I’m not saying that the update broke my code - I just can’t find whatever did break my code, and I noticed that the route in question was working before the update but does not work now, after the update. Probably, the problem was caused by something I did, since I’m pretty new to Meteor, and there’s a lot I don’t know.

I searched through all my recent commits, as well as the template files and their helpers, and the router.js file, for any changes that might have caused this. But I couldn’t find anything.

Then I found that if I change definition of the route (in /lib/router.js) to ‘/burping/cow’ or ‘/nice/mercedes’ or even ‘/post/new’ (no ‘s’), then it worked - I saw the new post form again.

But, for whatever reason, now when the route is set to the URL “/posts/new” (with a plural “posts”), I am instead redirected to the notFound template.

I double-checked all the template names (in the name="" attribute) and the names passed to Iron Router - everything there is matching as it should be.

It’s a strange problem, and I am pulling my hair out trying to find the source of the issue. Can anyone tell what the problem might be? Thanks


#2

I’ve been troubleshooting/messing around with this some more, trying to find the problem.

I noticed that I get the 404 template whenever “posts” is plural in the route: e.g. /posts/create

But, if I change it to post singular: e.g. /post/create, then it renders the post creation form, like it should, no matter what the verb is at the end of the route (new, create, whatever).

Is there anything in Meteor or Iron Router governing the nature of nouns and verbs in a REST style or any sort?


#3

No there is nothing special in Iron router that treats plurals differently, there is in face no REST happening anywhere in the basic meteor stack, its all done through DDP. I would be happy to take a look at your code in order to debug the problem, reply with a link to github or bitbucket would be easiest.


#4

Thank you. I was actually just in the process of creating a branch so I could show you both versions, when I think I figured out what the problem is.

It’s not (of course) a restriction with regard to RESTful routes.

The problem is that there is another route (also following a general RESTful pattern) for viewing posts:

// Single post view Router.route('/posts/:_id', { name: 'postPage', data: function() { return Posts.findOne(this.params._id); } });

And, whenever you attempt to load a route beginning with /posts, of course Meteor thinks you’re intending to look for a single post, so it tries to find a post with the id “new” (i.e. from the route /posts/new) and fails.

I wanted the URL scheme in the app to follow a general RESTful pattern, which is why I changed the post creation route from /submit to /posts/new – but evidently, the book’s authors had a good reason for not doing that. :wink:

I don’t know why I couldn’t see this yesterday when I posted about it - I’d just been staring at code for too many hours, I guess.