A plugin that is outside of the default request pipeline

plugins

(Salman, Freelance Developer) #1

If you currently create a simple controller (either via a plugin on just straight into the core) you run into issues.

For example if I just want to create a simple controller that uses my own simple layout:

class BlueController < ActionController::Base
	layout "blank"
  def index
  	@user = User.first
  	render 'blue/index'
  end
end

http://localhost:3000/blue/index

I get an error:

ActionController::RoutingError - uninitialized constant ApplicationHelper::CanonicalURL:
  actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:71:in `rescue in controller'
  actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:66:in `controller'
  actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:46:in `call'
  actionpack (4.1.8) lib/action_dispatch/journey/router.rb:73:in `block in call'
  actionpack (4.1.8) lib/action_dispatch/journey/router.rb:59:in `call'
  actionpack (4.1.8) lib/action_dispatch/routing/route_set.rb:678:in `call'
  rack-protection (1.5.3) lib/rack/protection/frame_options.rb:31:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/strategy.rb:186:in `call!'
  omniauth (1.2.2) lib/omniauth/strategy.rb:164:in `call'
  omniauth (1.2.2) lib/omniauth/builder.rb:59:in `call'
  rack (1.5.2) lib/rack/conditionalget.rb:25:in `call'
  rack (1.5.2) lib/rack/head.rb:11:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/params_parser.rb:27:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/flash.rb:254:in `call'
  message_bus (1.0.6) lib/message_bus/rack/middleware.rb:55:in `call'
  rack (1.5.2) lib/rack/session/abstract/id.rb:225:in `context'
  rack (1.5.2) lib/rack/session/abstract/id.rb:220:in `call'
  actionpack (4.1.8) lib/action_dispatch/middleware/cookies.rb:560:in `call'

How can I create a controller in a plugin that has its own layout (maybe not even use emberjs etc), but can still use the CurrentUser functionality.
The check_xhr will throw an error if I don’t return json, is there a way around this? Or a plugin is always bound by this rule also?

Plugin bootstrap:
Is the preferred method to use the rails plugin generator or to manually create the plugin template?


(Sam Saffron) #2

Have a look at my blog plugin or the tags plugin, you need to introduce a rails engine.


(Kane York) #3

skip_before_fiter :check_xhr
skip_before_fiter :ensure_logged_in


(Salman, Freelance Developer) #4

Thanks, got it working.

BTW @sam, how did you setup your site with discourse being served up at the root domain + the sub-domain?

Is it just 2 nginx entries?

  1. root 2) discuss.samsaffron.com

I can see the BlogConstraint overrides the ‘/’ path.


(Sam Saffron) #5

in my case on my blog haproxy sends the traffic to docker and then plugin switches layout based on the domain name.