# Plugin Development: Beyond the Basics?

**URL:** <https://meta.discourse.org/t/plugin-development-beyond-the-basics/55754>\
**Category:** Development\
**Created:** [January 14, 2017, 10:28am UTC](https://meta.discourse.org/t/plugin-development-beyond-the-basics/55754 "2017-01-14T10:28:15Z")\
**Posts on this page:** 1\
**Showing post:** 2

<div class="post-metadata">

**Author:** ![gdpelican](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/gdpelican/32/81308_2.png) [@gdpelican](https://meta.discourse.org/u/gdpelican)\
**Post date:** [January 14, 2017, 11:34am UTC](https://meta.discourse.org/t/plugin-development-beyond-the-basics/55754/2 "2017-01-14T11:34:31Z")

</div>

If you haven’t found the [Ember docs](https://guides.emberjs.com/v2.10.0/) yet, they’re probably the best place to start if the question is ‘WTF are you, Ember?’

A rough outline of how you could tackle this plugin:

- Write a serializer which will output the data you need, given a file:

```plaintext
class FileSerializer < ActiveModel::Serializer
  attributes :filename, :href
end

```

- Write a rails controller method which use that serializer to return the files in a json format:

```ruby
class Globber::FilesController < ApplicationController
  def index
    @files = Dir.glob("files/**.*.rb")
    render json: ActiveModel::ArraySerializer.new(@files, each_serializer: FileSerializer)
  end
end

```

- Expose an endpoint so that Ember can access the controller method:

```plaintext
Discourse::Application.routes.append do
  get '/globber/files' => 'globber/files#index'
end

```

- On the ember side, make an ajax call which hits that endpoint and returns the json data you’re looking for:

```plaintext
import { ajax } from 'discourse/lib/ajax'
ajax('/globber/files').then((data) => { this.set('files', data) })
# ^^ 'files' is now a property that's accessible in the view

```

- Then, in the ember template of the javascript controller, you can iterate through the files and display them seasoned to taste:

```plaintext
{{#each file as |files|}}
  <a href={{file.href}}>{{file.name}}</a>
{{/each}}

```

(NB: all code in this post is untested and subject to crappiness)

The only way I ever learned anything about writing plugins for Discourse was reading other people’s code (well, and asking questions on here ;)), so likely that’s the best way to go if you’re looking to expand your knowledge further.

---

_[View the full topic](https://meta.discourse.org/t/plugin-development-beyond-the-basics/55754)._
