Some basic questions about discourse and rails


(SMHassanAlavi) #1

I worked with discourse about 10 months and created some plugin for this. but I have still some questions that I didn’t find the answers during these 10 months and searching in web. So I decided to ask them here Because I see many discourse and rails expert here.

my questions:

1-What is the relation between emberjs, handlebars and html.erb files?When we saw a page,(for example main page)which code is loaded?

2-Who exactly handle the discourse Front-End? I know MVC and I know there is a view that controlled by controller but I don’t know What is the view in discourse? (Are they just in app/views ?)

3-how to create a plugin to update itself after sometimes without refreshing the page? When I receive a like, a new notification will appear near my avatar after a few seconds without refreshing the page. What should I do to create a plugin to update it self after a few seconds and of course I need it not to slow the page.

4-To develop good front-end plugin (that can make any change in rendered pages), Which programming language should I know(except CSS :slight_smile: )?(My guess is EmberJS for this question)


(Vinoth Kannan) #2
  1. .html.erb files are only for bots and non-javascript browsers. In source you can see many html entities inside <noscript data-path="/"> tag. That all rendered in server side using Rails and .html.erb files.
    And you can see an empty <section id='main'> tag in source. This is where handlebar files with ember will be rendered after the javascript and ember initialization.
    Almost all the UI you see visibly in your browser are ember rendered html after all initializations.

  2. Discourse Front-End handlbed by EmberJS. Most of the Ember views are in /app/assets/javascripts/discourse/templates and /app/assets/javascripts/admin/templates not inside /app/views/ (It is .html.erb files for Rails.).

  3. I guess in ember, notifications are received from rails by message bus.
    If you just want to run a script after some time interval then just use Ember.run.later function.

  4. Yes. EmberJS :+1:.
    Also if you only need to change the front-end then you can try developing themes / theme components instead of plugins.


(SMHassanAlavi) #3

So after initializing, this tag shouldn’t be empty because there is something there but it is still empty. What this empty tag does?


(Vinoth Kannan) #4

Empty #main tag is placeholder for Ember to render html elements.

As you see in above code we are commanding Ember to render it’s output to #main section tag.