Adding Dynamic Routes in a Plugin

AI-generated summary

Adding Dynamic Routes in a Plugin

tjaco is creating a Discourse plugin that requires dynamic routes for displaying individual posts. The desired routing structure is this.route('posts'); this.route('posts.show', { path: 'posts/:post_id' }, which has been successfully implemented in plain Ember. However, when attempting to replicate this in Discourse, an error occurs, returning an undefined property ‘post’ for undefined.

tjaco suspects that the issue may be related to the Discourse store (Ember Data equivalent) and wonders if the object needs to be added to the store or if there’s a way to bypass it. vinothkannans suggested a guide on creating Discourse plugins, but tjaco has already successfully implemented admin interfaces using that guide, which doesn’t involve dynamic routes.

Hi Everyone,

to start of, I am pretty new at Ember and Discourse so excuse anything I ask that should be self explanatory… :slight_smile:

I am creating a plugin for a client and need to define some dynamic routes. I have done this in plane ember within 15 minutes, but can’t seem to get this to work in discourse.

Basically I need a routing structure like this:

Basically I have posts and need to define a show view per post.

Have these routes setup in plain Ember:

this.route('posts');
this.route('posts.show', { path: 'posts/:post_id' }

I have a controller setup that just returns some json, so the actual post_id wouldn’t matter.

Basically I understand that once you have a dynamic route, you should define a specific route that returns a model, which you can then use in the template.
Currently it is not working and returns a undefined property ‘post’ for undefined. So I’m guessing I need to do something more in discourse to get this to work.

Can someone point me in the right direction and/or point me to some documentation where I can get this information?

Thanks!

Tjaco

Did you checked this Developing Discourse Plugins - Part 5 - Add an admin interface?

Yes I got that working just fine, but that is not using any dynamic route functionality.

I think the main this is that it tries to find the object in the discourse store. That is the discourse version of ember data(right?) and then it fails. So is there something I need to do to add it to the store? Or possibly ignore it going to the store?