Plugin Controller Method never called

I there,
I want to create a plugin with new routes and an own server-controller.
My problem is that discourse knows that there is the controller and expects the method for the route.
But the code in my controller method is never called. :frowning:

plugin:

Disraptor::Engine.routes.draw do
  root to: "disraptor#show"
  get /testroute => "disraptor#show"
end

Discourse::Application.routes.prepend do
  mount Disraptor::Engine, at: "/"
end

Controller:

class Disraptor::DisraptorController < ApplicationController
  def show
    #never gets called :(
    Rails.logger.info "test"
  end
end

I donā€™t know whats the problem here, I just want to mount my plugin Engine at the root route and add an additional route and do some stuff on the server.

This guy has the same problem that his controller method never gets called:
https://meta.discourse.org/t/help-wanted-on-plugin-controller/40258

i havenā€™t tried mounting at the root level, but hereā€™s how Iā€™m doing in the voting plugin:

https://github.com/joebuhlig/discourse-feature-voting/blob/master/plugin.rb#L219

https://github.com/joebuhlig/discourse-feature-voting/blob/master/config/routes.rb#L1

https://github.com/joebuhlig/discourse-feature-voting/blob/master/app/controllers/discourse_feature_voting/votes_controller.rb#L5

4 Likes

Pardon the double reply. I was looking at this again and it looks like youā€™re trying to overwrite the root url for the whole thing. Youā€™re mounting the engine at the root and then assigning a new root controller/method within the engine. Is that what youā€™re trying to do? Thereā€™s likely going to be a collision there of some kind.

Thank you for your answer.
Yeah I also tried to mount it at a different route
this is my plugin.rb now:

enabled_site_setting :disraptor_enabled
register_asset 'stylesheets/disraptor.scss'

add_admin_route 'disraptor.title', 'disraptor'

load File.expand_path('../lib/disraptor.rb', __FILE__)
load File.expand_path('../lib/disraptor/engine.rb', __FILE__)

after_initialize do
  require_dependency "application_controller"
  load File.expand_path('../lib/disraptor/route.rb', __FILE__)
  load File.expand_path('../lib/disraptor/route_serializer.rb', __FILE__)
  Discourse::Application.routes.append do
    mount ::Disraptor::Engine, at: "/disraptor"
    # add the routes for the admin interface
    get "/admin/plugins/disraptor" => "route#index", constraints: AdminConstraint.new
    get "/admin/plugins/disraptor/routes" => "route#index", constraints: AdminConstraint.new
    post "/admin/plugins/disraptor/routes" => "route#create", constraints: AdminConstraint.new
    get "/admin/plugins/disraptor/routes/:id" => "route#show", constraints: AdminConstraint.new
    put "/admin/plugins/disraptor/routes/:id" => "route#update", constraints: AdminConstraint.new
    delete "/admin/plugins/disraptor/routes/:id" => "route#destroy", constraints: AdminConstraint.new
  end
end

and the routes.rb:

Disraptor::Engine.routes.draw do
  root to: 'disraptor#show'
  get '/disraptor' => 'disraptor#show'
end

and my disraptor_controller.rb:

module Disraptor
  class DisraptorController < ::ApplicationController
    requires_plugin Disraptor.plugin_name
    layout 'disraptor'
    
    def show
      Rails.logger.info "test"
    end
  end
end

the stuff for the admin routes works but not for the disraptor controller.
Does this problem maybe has something to do with the engine?

Can you share the error trace it gives you?

1 Like

Hi, there is no error trace at all but here is what I tried next:

I tried it again with a fresh installation of discourse.
Then I just added a new plugin folder with a plugib.rb:

# name: Disraptor
# about: A super simple plugin to demonstrate how plugins work
# version: 0.0.1
# authors: Awesome Plugin Developer

enabled_site_setting :disraptor_enabled

# load the engine
load File.expand_path('../lib/disraptor/engine.rb', __FILE__)

after_initialize do
  Discourse::Application.routes.append do
    mount ::Disraptor::Engine, at: "/disraptor"
  end
end

engine.rb:

module Disraptor
  class Engine < ::Rails::Engine
    isolate_namespace Disraptor
  end
end

routes.rb:

Disraptor::Engine.routes.draw do
  root to: "site#showroute"
  get "/test" => "site#showroute"
end

site_controller.rb:

module Disraptor
  class SiteController < ::ApplicationController
    requires_plugin 'Disraptor'
    def showroute
      render text: "test"
      Rails.logger.info "test"
    end
  end
end

and a settings.yml:

plugins:
  disraptor_enabled:
    default: true
    client: true

the code in the showroute method also never gets called.
this is the log-print when I access http://localhost:4000/disraptor/test.
At least I would expect the info-log print from the controller somewhere here.

Listening on 0.0.0.0:3000, CTRL+C to stop
D, [2016-04-27T10:25:14.024166 #1804] DEBUG -- : 
D, [2016-04-27T10:25:14.032335 #1804] DEBUG -- : 
I, [2016-04-27T10:25:14.033077 #1804]  INFO -- : Started GET "/disraptor/test" for 10.0.2.2 at 2016-04-27 10:25:14 -0400
D, [2016-04-27T10:25:15.032232 #1804] DEBUG -- :   ActiveRecord::SchemaMigration Load (2.5ms)  SELECT "schema_migrations".* FROM "schema_migrations"
D, [2016-04-27T10:25:15.267561 #1804] DEBUG -- :   Permalink Exists (2.7ms)  SELECT  1 AS one FROM "permalinks" WHERE "permalinks"."url" = 'disraptor/test' LIMIT 1  [["url", "disraptor/test"]]
I, [2016-04-27T10:25:15.301483 #1804]  INFO -- : Processing by Disraptor::SiteController#showroute as HTML
D, [2016-04-27T10:25:15.312852 #1804] DEBUG -- :   User Load (3.0ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:25:15.564756 #1804] DEBUG -- :    (2.5ms)  SELECT "groups"."id", "groups"."name" FROM "groups"  ORDER BY "groups"."name" ASC
D, [2016-04-27T10:25:15.593559 #1804] DEBUG -- :    (6.5ms)  SELECT categories.id FROM "categories" WHERE "categories"."read_restricted" = 't'  [["read_restricted", true]]
D, [2016-04-27T10:25:15.606627 #1804] DEBUG -- :   Category Load (6.0ms)  SELECT categories.*, t.slug topic_slug FROM "categories" LEFT JOIN topics t on t.id = categories.topic_id WHERE (NOT categories.read_restricted or categories.id in (2,4))  ORDER BY "categories"."position" ASC
D, [2016-04-27T10:25:15.607889 #1804] DEBUG -- :   UserVisit Load (3.6ms)  SELECT  "user_visits".* FROM "user_visits" WHERE "user_visits"."user_id" = 2 AND "user_visits"."visited_at" = '2016-04-27' LIMIT 1  [["user_id", 2], ["visited_at", Wed, 27 Apr 2016]]
D, [2016-04-27T10:25:15.665444 #1804] DEBUG -- :    (8.4ms)  SELECT "categories"."id" FROM "categories"
D, [2016-04-27T10:25:15.690818 #1804] DEBUG -- :    (2.5ms)  SELECT "category_users"."category_id", "category_users"."notification_level" FROM "category_users" WHERE "category_users"."user_id" = 2
D, [2016-04-27T10:25:15.706722 #1804] DEBUG -- :   SQL (43.7ms)  UPDATE "users" SET "last_seen_at" = '2016-04-27 14:25:15.363892' WHERE "users"."id" = 2  [["id", 2]]
D, [2016-04-27T10:25:15.708963 #1804] DEBUG -- :   PostActionType Load (2.7ms)  SELECT "post_action_types".* FROM "post_action_types"  ORDER BY position asc
D, [2016-04-27T10:25:15.834216 #1804] DEBUG -- :    (2.5ms)  SELECT "translation_overrides"."translation_key", "translation_overrides"."value", "translation_overrides"."compiled_js" FROM "translation_overrides" WHERE "translation_overrides"."locale" = 'en'  [["locale", :en]]
D, [2016-04-27T10:25:15.851177 #1804] DEBUG -- :   PostActionType Load (2.8ms)  SELECT "post_action_types".* FROM "post_action_types" WHERE "post_action_types"."name_key" IN ('inappropriate', 'spam', 'notify_moderators')  ORDER BY position asc
D, [2016-04-27T10:25:15.873528 #1804] DEBUG -- :   UserField Load (3.5ms)  SELECT "user_fields".* FROM "user_fields"
D, [2016-04-27T10:25:15.920356 #1804] DEBUG -- :   SiteCustomization Load (2.3ms)  SELECT "site_customizations".* FROM "site_customizations" WHERE "site_customizations"."enabled" = 't'  ORDER BY "site_customizations"."name" ASC  [["enabled", true]]
D, [2016-04-27T10:25:15.959208 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT "site_customizations".* FROM "site_customizations" WHERE "site_customizations"."enabled" = 't'  ORDER BY "site_customizations"."name" ASC  [["enabled", true]]
D, [2016-04-27T10:25:15.980698 #1804] DEBUG -- :   Topic Load (2.6ms)  SELECT  "topics".* FROM "topics" WHERE ("topics"."deleted_at" IS NULL) AND "topics"."archetype" = 'banner'  ORDER BY "topics"."id" ASC LIMIT 1  [["archetype", "banner"]]
D, [2016-04-27T10:25:16.044649 #1804] DEBUG -- :    (2.8ms)  SELECT COUNT(*) FROM "notifications" WHERE "notifications"."user_id" = 2 AND (read = false)  [["user_id", 2]]
D, [2016-04-27T10:25:16.078315 #1804] DEBUG -- :   UserStat Load (1.7ms)  SELECT  "user_stats".* FROM "user_stats" WHERE "user_stats"."user_id" = 2 LIMIT 1  [["user_id", 2]]
D, [2016-04-27T10:25:16.116261 #1804] DEBUG -- :   UserOption Load (2.0ms)  SELECT  "user_options".* FROM "user_options" WHERE "user_options"."user_id" = 2 LIMIT 1  [["user_id", 2]]
D, [2016-04-27T10:25:16.157429 #1804] DEBUG -- :    (2.7ms)  SELECT "category_users"."category_id" FROM "category_users" WHERE "category_users"."user_id" = 2 AND "category_users"."notification_level" = 0  [["user_id", 2], ["notification_level", 0]]
D, [2016-04-27T10:25:16.179991 #1804] DEBUG -- :   UserProfile Load (2.2ms)  SELECT  "user_profiles".* FROM "user_profiles" WHERE "user_profiles"."user_id" = 2 LIMIT 1  [["user_id", 2]]
D, [2016-04-27T10:25:16.217825 #1804] DEBUG -- :    (2.6ms)  SELECT COUNT(*) FROM "queued_posts" WHERE "queued_posts"."state" = 1 AND "queued_posts"."queue" = 'default'  [["state", 1]]
D, [2016-04-27T10:25:16.224579 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT COUNT(*) FROM "queued_posts" WHERE "queued_posts"."state" = 1 AND "queued_posts"."queue" = 'default'  [["state", 1]]
I, [2016-04-27T10:25:16.277286 #1804]  INFO -- :   Rendered default/empty.html.erb within layouts/application (2.8ms)
D, [2016-04-27T10:25:16.299826 #1804] DEBUG -- :   ColorScheme Load (2.0ms)  SELECT  "color_schemes".* FROM "color_schemes" WHERE "color_schemes"."versioned_id" IS NULL AND "color_schemes"."enabled" = 't' LIMIT 1  [["enabled", true]]
I, [2016-04-27T10:25:16.403547 #1804]  INFO -- :   Rendered layouts/_head.html.erb (110.8ms)
I, [2016-04-27T10:26:18.767477 #1804]  INFO -- :   Rendered common/_special_font_face.html.erb (62263.7ms)
D, [2016-04-27T10:26:18.780559 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT  "color_schemes".* FROM "color_schemes" WHERE "color_schemes"."versioned_id" IS NULL AND "color_schemes"."enabled" = 't' LIMIT 1  [["enabled", true]]
D, [2016-04-27T10:26:18.789636 #1804] DEBUG -- :    (2.7ms)  SELECT  "categories"."updated_at" FROM "categories" WHERE (background_url IS NOT NULL and background_url != '')  ORDER BY updated_at desc LIMIT 1
D, [2016-04-27T10:26:19.021500 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT  "color_schemes".* FROM "color_schemes" WHERE "color_schemes"."versioned_id" IS NULL AND "color_schemes"."enabled" = 't' LIMIT 1  [["enabled", true]]
D, [2016-04-27T10:26:19.031050 #1804] DEBUG -- :    (2.2ms)  SELECT  "categories"."updated_at" FROM "categories" WHERE (background_url IS NOT NULL and background_url != '')  ORDER BY updated_at desc LIMIT 1
D, [2016-04-27T10:26:19.130216 #1804] DEBUG -- :    (3.2ms)  SELECT "site_customizations"."stylesheet_baked" FROM "site_customizations" WHERE "site_customizations"."enabled" = 't'  ORDER BY "site_customizations"."name" ASC  [["enabled", true]]
I, [2016-04-27T10:26:19.138218 #1804]  INFO -- :   Rendered common/_discourse_stylesheet.html.erb (360.2ms)
D, [2016-04-27T10:26:42.960328 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT "site_customizations".* FROM "site_customizations" WHERE "site_customizations"."enabled" = 't'  ORDER BY "site_customizations"."name" ASC  [["enabled", true]]
I, [2016-04-27T10:26:42.978818 #1804]  INFO -- :   Rendered application/_header.html.erb (1.1ms)
D, [2016-04-27T10:26:42.984612 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT "site_customizations".* FROM "site_customizations" WHERE "site_customizations"."enabled" = 't'  ORDER BY "site_customizations"."name" ASC  [["enabled", true]]
I, [2016-04-27T10:26:43.180211 #1804]  INFO -- :   Rendered common/_discourse_javascript.html.erb (184.7ms)
D, [2016-04-27T10:26:43.185265 #1804] DEBUG -- :   CACHE (0.0ms)  SELECT "site_customizations".* FROM "site_customizations" WHERE "site_customizations"."enabled" = 't'  ORDER BY "site_customizations"."name" ASC  [["enabled", true]]
I, [2016-04-27T10:26:43.192504 #1804]  INFO -- : Completed 200 OK in 87886ms (Views: 86907.2ms | ActiveRecord: 143.8ms)
D, [2016-04-27T10:26:43.329064 #1804] DEBUG -- : 
D, [2016-04-27T10:26:43.329272 #1804] DEBUG -- : 
I, [2016-04-27T10:26:43.329728 #1804]  INFO -- : Started GET "/stylesheets/desktop.css?body=1" for 10.0.2.2 at 2016-04-27 10:26:43 -0400
I, [2016-04-27T10:26:43.926898 #1804]  INFO -- : Processing by StylesheetsController#show as HTML
I, [2016-04-27T10:26:43.931376 #1804]  INFO -- :   Parameters: {"body"=>"1", "name"=>"desktop"}
D, [2016-04-27T10:26:43.937313 #1804] DEBUG -- :   User Load (0.9ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:26:43.952901 #1804] DEBUG -- :    (1.0ms)  SELECT "stylesheet_cache"."created_at" FROM "stylesheet_cache" WHERE "stylesheet_cache"."target" = 'desktop'  ORDER BY id desc  [["target", "desktop"]]
I, [2016-04-27T10:26:43.962404 #1804]  INFO -- : Sent file /vagrant/tmp/stylesheet-cache/desktop.css (0.5ms)
I, [2016-04-27T10:26:43.999774 #1804]  INFO -- : Completed 200 OK in 64ms (ActiveRecord: 3.3ms)
D, [2016-04-27T10:26:44.007476 #1804] DEBUG -- :   UserVisit Load (1.7ms)  SELECT  "user_visits".* FROM "user_visits" WHERE "user_visits"."user_id" = 2 AND "user_visits"."visited_at" = '2016-04-27' LIMIT 1  [["user_id", 2], ["visited_at", Wed, 27 Apr 2016]]
D, [2016-04-27T10:26:44.020635 #1804] DEBUG -- : 
D, [2016-04-27T10:26:44.022744 #1804] DEBUG -- : 
I, [2016-04-27T10:26:44.023114 #1804]  INFO -- : Started GET "/stylesheets/admin.css?body=1" for 10.0.2.2 at 2016-04-27 10:26:44 -0400
D, [2016-04-27T10:26:44.208716 #1804] DEBUG -- :   SQL (196.1ms)  UPDATE "users" SET "last_seen_at" = '2016-04-27 14:26:43.942690' WHERE "users"."id" = 2  [["id", 2]]
I, [2016-04-27T10:26:44.284135 #1804]  INFO -- : Processing by StylesheetsController#show as HTML
I, [2016-04-27T10:26:44.291731 #1804]  INFO -- :   Parameters: {"body"=>"1", "name"=>"admin"}
D, [2016-04-27T10:26:44.298228 #1804] DEBUG -- :   User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:26:44.305253 #1804] DEBUG -- :    (0.5ms)  SELECT "stylesheet_cache"."created_at" FROM "stylesheet_cache" WHERE "stylesheet_cache"."target" = 'admin'  ORDER BY id desc  [["target", "admin"]]
I, [2016-04-27T10:26:44.312916 #1804]  INFO -- : Sent file /vagrant/tmp/stylesheet-cache/admin.css (0.3ms)
I, [2016-04-27T10:26:44.317918 #1804]  INFO -- : Completed 200 OK in 21ms (ActiveRecord: 1.1ms)
D, [2016-04-27T10:27:13.706459 #1804] DEBUG -- : 
D, [2016-04-27T10:27:13.707090 #1804] DEBUG -- : 
I, [2016-04-27T10:27:13.707715 #1804]  INFO -- : Started GET "/404-body?_=1461767230638" for 10.0.2.2 at 2016-04-27 10:27:13 -0400
I, [2016-04-27T10:27:13.914026 #1804]  INFO -- : Processing by ExceptionsController#not_found_body as HTML
I, [2016-04-27T10:27:13.918441 #1804]  INFO -- :   Parameters: {"_"=>"1461767230638"}
D, [2016-04-27T10:27:13.924641 #1804] DEBUG -- :   User Load (2.0ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:27:13.937039 #1804] DEBUG -- :    (1.9ms)  SELECT "categories"."topic_id" FROM "categories"
D, [2016-04-27T10:27:13.944662 #1804] DEBUG -- :    (1.6ms)  SELECT "categories"."id" FROM "categories" WHERE "categories"."read_restricted" = 'f'  [["read_restricted", false]]
D, [2016-04-27T10:27:13.972539 #1804] DEBUG -- :   SQL (7.8ms)  SELECT .....
D, [2016-04-27T10:27:13.994738 #1804] DEBUG -- :   Topic Load (3.8ms)  SELECT  "topics".* FROM "topics" WHERE ("topics"."deleted_at" IS NULL) AND ("topics"."id" NOT IN (1, 3, 2)) AND (topics.archetype <> 'private_message') AND "topics"."visible" = 't' AND (category_id IS NULL OR category_id IN (
           SELECT c.id FROM categories c
           WHERE NOT c.read_restricted))  ORDER BY created_at desc LIMIT 10  [["visible", true]]
D, [2016-04-27T10:27:14.043489 #1804] DEBUG -- :   Category Load (2.1ms)  SELECT  "categories".* FROM "categories" WHERE "categories"."id" = 3 LIMIT 1  [["id", 3]]
D, [2016-04-27T10:27:14.053863 #1804] DEBUG -- :   Category Load (1.7ms)  SELECT  "categories".* FROM "categories" WHERE "categories"."id" = 1 LIMIT 1  [["id", 1]]
I, [2016-04-27T10:27:14.058787 #1804]  INFO -- :   Rendered exceptions/not_found.html.erb (69.8ms)
I, [2016-04-27T10:27:14.065158 #1804]  INFO -- :   Rendered text template (0.0ms)
I, [2016-04-27T10:27:14.067440 #1804]  INFO -- : Completed 200 OK in 145ms (Views: 4.3ms | ActiveRecord: 20.9ms)
D, [2016-04-27T10:27:14.078353 #1804] DEBUG -- : 
D, [2016-04-27T10:27:14.078540 #1804] DEBUG -- : 
I, [2016-04-27T10:27:14.078836 #1804]  INFO -- : Started GET "/about/live_post_counts.json?_=1461767230639" for 10.0.2.2 at 2016-04-27 10:27:14 -0400
I, [2016-04-27T10:27:14.274221 #1804]  INFO -- : Processing by AboutController#live_post_counts as JSON
I, [2016-04-27T10:27:14.280119 #1804]  INFO -- :   Parameters: {"_"=>"1461767230639"}
D, [2016-04-27T10:27:14.286324 #1804] DEBUG -- :   User Load (1.9ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:27:14.300917 #1804] DEBUG -- :    (6.9ms)  SELECT "categories"."topic_id" FROM "categories"
D, [2016-04-27T10:27:14.323524 #1804] DEBUG -- :    (4.0ms)  SELECT COUNT(*) FROM "topics" WHERE ("topics"."deleted_at" IS NULL) AND (topics.archetype <> 'private_message') AND "topics"."visible" = 't' AND (category_id IS NULL OR category_id IN (
           SELECT c.id FROM categories c
           WHERE NOT c.read_restricted)) AND ("topics"."id" NOT IN (1, 3, 2))  [["visible", true]]
D, [2016-04-27T10:27:14.334184 #1804] DEBUG -- :    (2.1ms)  SELECT SUM("topics"."posts_count") FROM "topics" WHERE ("topics"."deleted_at" IS NULL) AND (topics.archetype <> 'private_message') AND "topics"."visible" = 't' AND (category_id IS NULL OR category_id IN (
           SELECT c.id FROM categories c
           WHERE NOT c.read_restricted)) AND ("topics"."id" NOT IN (1, 3, 2))  [["visible", true]]
I, [2016-04-27T10:27:14.341678 #1804]  INFO -- : Completed 200 OK in 58ms (Views: 0.3ms | ActiveRecord: 24.9ms)
D, [2016-04-27T10:27:15.248080 #1804] DEBUG -- :   User Load (0.7ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:27:15.266296 #1804] DEBUG -- :    (8.4ms)  SELECT "groups"."id" FROM "groups"
D, [2016-04-27T10:27:15.275993 #1804] DEBUG -- : Delivering messages [{"global_id":-1,"message_id":-1,"channel":"/__status","data":{"/new":11,"/latest":14,"/unread/2":0,"/delete":0,"/recover":0,"/global/asset-version":1,"/site/banner":0,"/file-change":0,"/logout":0,"/site/read-only":0,"/flagged_counts":0,"/queue_counts":0,"/notification/2":1,"/categories":0,"/client_settings":0,"/notification-alert/2":0}}] to client 23844a809bf3427b8fa9af33723782b7 for user 2 (chunked)
D, [2016-04-27T10:27:40.276067 #1804] DEBUG -- : Delivering messages [] to client 23844a809bf3427b8fa9af33723782b7 for user 2 (chunked)
D, [2016-04-27T10:27:41.233650 #1804] DEBUG -- :   User Load (0.8ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:27:41.239365 #1804] DEBUG -- :    (0.5ms)  SELECT "groups"."id" FROM "groups"
D, [2016-04-27T10:27:41.246622 #1804] DEBUG -- : Delivering messages [] to client 23844a809bf3427b8fa9af33723782b7 for user 2 (chunked)
D, [2016-04-27T10:28:06.246788 #1804] DEBUG -- : Delivering messages [] to client 23844a809bf3427b8fa9af33723782b7 for user 2 (chunked)
D, [2016-04-27T10:28:07.232273 #1804] DEBUG -- :   User Load (0.5ms)  SELECT  "users".* FROM "users" WHERE "users"."auth_token" = 'ac478c77c48985c112e4f457c80dc3e9' LIMIT 1  [["auth_token", "ac478c77c48985c112e4f457c80dc3e9"]]
D, [2016-04-27T10:28:07.235803 #1804] DEBUG -- :    (0.4ms)  SELECT "groups"."id" FROM "groups"
D, [2016-04-27T10:28:07.240967 #1804] DEBUG -- : Delivering messages [] to client 23844a809bf3427b8fa9af33723782b7 for user 2 (chunked)

Two things I noticed after copy/pasting your code into my development env:

  1. General rule of thumb with controllers is to name them with a plural. So I changed SiteController to SitesController.
  2. Make sure that controller is in this path: app/controllers/disraptor/sites_controller.rb.

Once I made those two changes, it was able to run without errors. It was giving me an ā€œuninitialized constantā€ error to start. It still needs some work to get it to show something other than the 404 but that will get your routes working.

How to do that in a plugin?

Hereā€™s how it works in the voting plugin:

https://github.com/joebuhlig/discourse-feature-voting/blob/master/app/controllers/discourse_feature_voting/votes_controller.rb

I changed the name of the controller and checked its path, but still nothing happens in the method.
I uploaded my example code to Github

How are you doing your development? I cloned your repo and tried to run it with no changes and it gives errors right away that you can start to trace.

I am developing with a discourse in a vagrant virtual machine.
On my environment the template is loaded
(I added the template just to test if the controller does something)

So that tells me everything is working. No?

no, the problem is still that the code in showroute is not called.
https://github.com/EndruK/disraptor/blob/master/app/controllers/disraptor/sites_controller.rb

Iā€™m not sure you can display views through controllers without an Ember route map. The only time Iā€™ve called Ruby controller methods is through ajax calls. Take a look at the plugin how-to and look at the section where Robin talks about the route map.

2 Likes

Ah nice that was it!
I needed an ember controller with an ajax method to call the server controller method correctly.

Thank you for that!

2 Likes