I’ve had fairly good experiences using plugin-outlets, but I wanted to improve my Discourse plugin dev chops.
So I decided I’d try to see if I could put together Ruby and Ember code by following this (that seems to be more about modifying Core files than plugins)
I have a plugin.rb
# name: discourse-newpage
# about: learning exercise
# version: 0.1
# authors: Mittineague
# url: https://github.com/Mittineague/no-repo-for-this.git
enabled_site_setting :mitt_newpage_enabled
module ::DiscourseNewpage
def self.plugin_name
'discourse-newpage'.freeze
end
end
after_initialize do
module ::DiscourseNewpage
class Engine < ::Rails::Engine
engine_name "discourse-newpage"
isolate_namespace DiscourseNewpage
end
end
DiscourseNewpage::Engine.routes.draw do
get '/newpage' => 'newpages#index'
get '/newpage/:id' => 'newpages#show'
end
Discourse::Application.routes.append do
mount DiscourseNewpage::Engine, at: "/"
end
require_dependency 'application_controller'
class DiscourseNewpage::NewpagesController < ::ApplicationController
def index
render json: { name: "donut", description: "delicious!" }
rescue StandardError => e
render_json_error e.message
# render text: 'Just sayin' # at newpage.json !?
# render inline: "<%= 'hello , ' * 3 + 'again' %>" # at newpage.json !?
end
def show
render json: { name: "cake", description: "moist!" }
rescue StandardError => e
render_json_error e.message
# render text: 'Just sayin' # at newpage.json !?
# render inline: "<%= 'hello , ' * 3 + 'again' %>" # at newpage.json !?
end
end
end
By going to localhost:3000/newpage.json or localhost:3000/newpage/3.json I get the index and show (which oddly can also display “text” and “inline” by going to “json” when they are the “render”)
I have a newpage-route-map.js.es6 file that currently is like
export default {
map(function(){
this.route('newpage', { path: '/index' });
this.route('newpage/:id', { path: '/show' });
});
}
and I have templates/.hbs and routes/.js.es6 files for “index” and “show”
After spending quite a bit of time the past few days trying countless variations of uppercase, lowercase, camelcase, slashes, periods, hyphens, different resources, different paths, etc. etc. etc. I have gone well beyond making educated best guesses and gone into throwing against the wall to see if it sticks territory.
No matter what I have tried doing, without the “.json” I invariably get the “OOPS!” page.
Maybe I’m missing the obvious?
Maybe it is not possible at all?
Maybe I need to extend a different controller?
Any and all suggestions are most welcome. TIA