# Work with Rails

**URL:** <https://discuss.hotwired.dev/t/work-with-rails/43>\
**Category:** General\
**Created:** [February 6, 2018, 3:56pm UTC](https://discuss.hotwired.dev/t/work-with-rails/43 "2018-02-06T15:56:51Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![42thcoder](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/42thcoder/32/44_2.png) [@42thcoder](https://discuss.hotwired.dev/u/42thcoder)\
**Post date:** [February 6, 2018, 3:56pm UTC](https://discuss.hotwired.dev/t/work-with-rails/43/1 "2018-02-06T15:56:51Z")

</div>

What is the right way to organize JavaScript using stimulusjs in a Rails project?

---

<div class="post-metadata">

**Author:** ![javan](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/javan/32/594_2.png) [@javan](https://discuss.hotwired.dev/u/javan)\
**Post date:** [February 6, 2018, 7:10pm UTC](https://discuss.hotwired.dev/t/work-with-rails/43/2 "2018-02-06T19:10:35Z")

</div>

If you’re using [Webpacker](https://github.com/rails/webpacker), I suggest putting your controllers in `app/javascript/controllers/` and setting up your application in `app/javascript/packs/application.js`:

```auto
import { Application } from "stimulus"
import { definitionsFromContext } from "stimulus/webpack-helpers"

const application = Application.start()
const context = require.context("controllers", true, /.js$/)
application.load(definitionsFromContext(context))

```

Webpacker will soon have an automatic installer that creates the same structure: [https://github.com/rails/webpacker/pull/1244](https://github.com/rails/webpacker/pull/1244)

---

<div class="post-metadata">

**Author:** ![xdmx](https://avatars.discourse-cdn.com/v4/letter/x/53a042/32.png) [@xdmx](https://discuss.hotwired.dev/u/xdmx)\
**Post date:** [February 6, 2018, 10:25pm UTC](https://discuss.hotwired.dev/t/work-with-rails/43/3 "2018-02-06T22:25:46Z")

</div>

Do you suggest to only use `app/javascript/packs/application.js` a pack and then having all the stimulus code in the `app/javascript/controllrers`?

What about stylesheets and images? Should they be in a pack and then imported from the javascript, or just in the `assets/stylesheets` and `assets/images` as usual?

---

<div class="post-metadata">

**Author:** ![bdavidxyz](https://yyz1.discourse-cdn.com/flex027/user_avatar/discuss.hotwired.dev/bdavidxyz/32/63_2.png) [@bdavidxyz](https://discuss.hotwired.dev/u/bdavidxyz)\
**Post date:** [February 11, 2018, 8:12pm UTC](https://discuss.hotwired.dev/t/work-with-rails/43/4 "2018-02-11T20:12:45Z")

</div>

You can also use it with [plain old Javascript](https://github.com/bdavidxyz/stimulus-with-javascript)
