Git Product home page Git Product logo

Comments (3)

wuworkshop avatar wuworkshop commented on June 2, 2024 2

@redhoodie Was wondering the same thing. I think this Medium article does a good job of explaining it:

https://medium.com/@guilhermepejon/how-to-install-materialize-css-in-rails-6-0-0-beta2-using-webpack-347c03b7104e

from materialize-sass.

aurora-a-k-a-lightning avatar aurora-a-k-a-lightning commented on June 2, 2024 1

hello :)
i think i found a way to use the javascript of this gem in a default rails 6 app.

  1. enable webpacker to use .erb via rails webpacker:install:erb. this will add the line environment.loaders.prepend('erb', erb) to config/webpack/environment.js
  2. rename app/assets/javascript/packs/application.js -> app/assets/javascript/packs/application.js.erb
  3. 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.

Jmarques avatar Jmarques commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.