Comments (3)
@redhoodie Was wondering the same thing. I think this Medium article does a good job of explaining it:
from materialize-sass.
hello :)
i think i found a way to use the javascript of this gem in a default rails 6 app.
- enable webpacker to use .erb via
rails webpacker:install:erb
. this will add the lineenvironment.loaders.prepend('erb', erb)
to config/webpack/environment.js - rename app/assets/javascript/packs/application.js -> app/assets/javascript/packs/application.js.erb
- import materialize.js from the materialize gem into application.js.erb via ruby tags, so the file will look like this
(from a brand new rails app)
// This file is automatically compiled by Webpack, along with any other files
// present in this directory. You're encouraged to place your actual application logic in
// a relevant structure within app/javascript and only use these pack files to reference
// that code so it'll be compiled.
import Rails from "@rails/ujs"
import Turbolinks from "turbolinks"
import * as ActiveStorage from "@rails/activestorage"
import "channels"
Rails.start()
Turbolinks.start()
ActiveStorage.start()
// add this line at the bottom! be sure to place any materialize.js api calls after this is loaded
<%= File.read(File.join(Gem.loaded_specs['materialize-sass'].full_gem_path, 'assets', 'javascripts', 'materialize.js')) %>
Now we can use the materialize javascript api like in the documentation!
document.addEventListener('DOMContentLoaded', function() {
var elems = document.querySelectorAll('.sidenav');
var instances = M.Sidenav.init(elems, {}); // M is now defined :)
});
resources:
https://edgeguides.rubyonrails.org/webpacker.html
rails/webpacker#57 (comment)
nathanvda/cocoon#452 (comment)
from materialize-sass.
Is it me or since this is an engine this is not compatible with Webpacker?
So new default rails app can't use this gem.
from materialize-sass.
Related Issues (20)
- QUESTION: Using turbolinks causing sideNav issues with browsers back action HOT 1
- Thumb with the range is out of view HOT 1
- Support v1.0.0-beta HOT 2
- helper-text styling is off HOT 2
- JavaScript evens are not initialized since 1.0.0-alpha.1 HOT 3
- Usage step A causing "Fail to import not found or unreadable" HOT 6
- sideNav is not a function HOT 2
- Why no helpers? HOT 2
- undefined variable HOT 1
- Forms are broken in 1.0.0.rc2 HOT 3
- $map: #007bff is not a map for `map-has-key' HOT 4
- Sidenav-overlay active with sidenav-fixed HOT 3
- not upgraded the gem version yet HOT 1
- Navbar module not working.... HOT 3
- update materialize.js HOT 1
- How do I access the Materialize 'M' backup? HOT 1
- DatePicker closes immediately when clicked on in Chrome HOT 3
- Warning when using Rails 6 zeitwerk autoloading
- Publish new release? HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from materialize-sass.