Skip to content

Instantly share code, notes, and snippets.

@blahutka
Last active September 15, 2025 07:04
Show Gist options
  • Select an option

  • Save blahutka/2feddc5b31fb510bf3d66c5513f5b8b2 to your computer and use it in GitHub Desktop.

Select an option

Save blahutka/2feddc5b31fb510bf3d66c5513f5b8b2 to your computer and use it in GitHub Desktop.
This is Phlex & Stimulus controllers setup + SASS. It will load Stimulus and SASS/CSS files from from app/components/* directory.
# app/components/ui/button.rb
class Components::Ui::Button < Components::Base
def view_template
button class: "btn btn-primary", data: {controller: 'ui--button'} do
"Click me"
end
end
end
// app/components/ui/button_controller.js
import { Controller } from "@hotwired/stimulus"
export default class extends Controller {
connect() {
console.log("Button controller connected! ui--button ready")
}
}
// app/components/ui/_button.scss
button {
color: blue;
}
// app/assets/stylesheets/application.scss
@import "components/ui/button";
# config/initializers/assets.rb
Rails.application.config.assets.paths << Rails.root.join("app")
# config/environments/development.rb
config.importmap.cache_sweepers << Rails.root.join('app/components')
pin_all_from "app/components", under: "components", to: "components"
// app/javascript/controllers/index.js
//
// Import and register all your controllers from the importmap under controllers/*
import { application } from "controllers/application"
import { eagerLoadControllersFrom } from "@hotwired/stimulus-loading"
eagerLoadControllersFrom("controllers", application)
eagerLoadControllersFrom("components", application)
// app/assets/config/manifest.js
//
//= link_tree ../../components .js
@blahutka
Copy link
Author

blahutka commented Mar 6, 2025

Screenshot 2025-03-06 at 9 48 03

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment