# Get server-side controller method to be called via plugin route

**URL:** https://meta.discourse.org/t/get-server-side-controller-method-to-be-called-via-plugin-route/92186
**Category:** Development
**Created:** [July 12, 2018, 2:55pm UTC](https://meta.discourse.org/t/get-server-side-controller-method-to-be-called-via-plugin-route/92186 "2018-07-12T14:55:57Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [July 12, 2018, 2:55pm UTC](https://meta.discourse.org/t/get-server-side-controller-method-to-be-called-via-plugin-route/92186/1 "2018-07-12T14:55:57Z")

</div>

Assume I setup a route in my plugin like this:

**`plugin.rb`** :

```ruby
get '/css/styles.css' => 'plugin_routes#show'

```

**`./app/controllers/plugin_routes_controller.rb`** :

```ruby
class PluginRoutesController < ApplicationController
  def show
    Rails.logger.info '┌────────────┐'
    Rails.logger.info '│ Here we go │'
    Rails.logger.info '└────────────┘'
  end
end

```

Why is it that I get the following output when the method above is not actually being called? The _Here we go_ part is absent from the logger output. How do I get the `show` method from above to be called?

```plaintext
I, [2018-07-12T16:45:17.108958 #30583] INFO -- :
Processing by PluginRoutesController#show as CSS

```

I realize that I can process such a route by adding an appropriate route configuration to the frontend also and then send an AJAX request to the same URI. This will eventually call the mentioned `show` method. How do I accomplish this without going through the frontend?

* * *

Other topic with the same problem: [Plugin Controller Method never called - #15 by joebuhlig](https://meta.discourse.org/t/plugin-controller-method-never-called/42815/15). Its conclusion is to have an Ember controller in the frontend as well, but this is exactly what I try to avoid.

---

<div class="post-metadata">

### Author: ![kleinfreund](https://avatars.discourse-cdn.com/v4/letter/k/a6a055/32.png) [@kleinfreund](https://meta.discourse.org/u/kleinfreund)
#### Post date: [July 13, 2018, 9:33am UTC](https://meta.discourse.org/t/get-server-side-controller-method-to-be-called-via-plugin-route/92186/2 "2018-07-13T09:33:50Z")

</div>

Please, correct me if I’m wrong, but this has to do with this little line at the top of the controller:

```ruby
skip_before_action :check_xhr

```

Adding it to a controller will achieve the desired outcome of having a server-side-only route.

Is it possible to only skip this particular before action for requests with a certain content type (e.g. HTML)?

* * *

**Update** : My current solution works like this:

1. The before action `check_xhr` will be skipped
2. A new before action `check_xhr_for_documents` is added. It explicitly calls `check_xhr` when some condition is true (e.g. the request format is HTML)

```ruby
class PluginRoutesController < ApplicationController
  before_action :check_xhr_for_documents
  skip_before_action :check_xhr

  def show
    Rails.logger.info '┌────────────┐'
    Rails.logger.info '│ Here we go │'
    Rails.logger.info '└────────────┘'
  end

  private

  def check_xhr_for_documents
    if request.format == 'text/html'
      check_xhr
    end
  end
end

```
