Question: i use [multer](/questions/tagged/multer "show questions tagged 'multer'") according to it's readme file in github  

it's readme said call multer in [middleware](/questions/tagged/middleware "show questions tagged 'middleware'") like this: 

**app.js** 

```
var multer = require('multer')
app.post('/upload', upload.single('image'), function(req, res){})

```

but i defined my **function(req, res)** in another file - post.js - and my code in **app.js** looks like this: 

```
app.post('/upload', upload.single('image'), post.new)

```

how can i **require** multer only on post.js, almost like this: 

**post.js** 

```
 var multer = require('multer')
 module.exports.new = function(req, res){
     //access to req.file
 }

```

**app.js** 

```
 app.post('/upload', post.new)

```

Answer: 
Since rails expects your module naming to follow your file structure, your concern should be named:

```
module Api::Concerns::ErrorSerializer

```

Since you're including it in `Api::TemplatesController`, I would do:

```
class Api::TemplatesController < ApiController
  include Api::Concerns::ErrorSerializer
  ...
end

```

To help rails out with the constant lookup.
Thanks to the answer from @jvillian and [this blog post](http://jordifierro.com/rails-apicontroller-and-concerns), I was able to figure out the 'Rails' way to do this (since actually I will need the concern in all Api controllers, and also my api controller was outside the api namespace). So I'm posting this solution as (I think) it's the preferred way:

I moved the error\_serialzier.rb file into api/concerns and change the code to include the Api namespace:

```
module Api::Concerns::ErrorSerializer
  extend ActiveSupport::Concern
  ...
end

```

I also moved `api_controller.rb` file and put it inside the /api folder, and thus into the API module namespace, so now it looks like this:

```
class Api::ApiController < ActionController::API
  before_action :authenticate_api_user!
  include DeviseTokenAuth::Concerns::SetUserByToken 
  include Concerns::ErrorSerializer

  respond_to :json
end

```

This got rid of the uninitialized constant errors.