Problems when applying materialization when creating web pages in rubyonrails

Asked 2 years ago, Updated 2 years ago, 35 views

<title>Sns</title>
<%= csrf_meta_tags %>
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<%= stylesheet_link_tag    'application', media: 'all', 'data-turbolinks-track': 'reload' %>
<%= javascript_include_tag 'application', 'data-turbolinks-track': 'reload' %>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>

<nav>
  <div class="nav-wrapper">
    <a href="/" class="brand-logo">SNS</a>
    <a href="#" data-activates="mobile-demo" class="button-collapse"><i class="material-icons">menu</i></a>
    <ul class="right hide-on-med-and-down">
      <li><a href="/posts">Posts</a></li>
      <li><a href="#">Sign In</a></li>
      <li><a href="#">Sign up</a></li>
    </ul>
    <ul class="side-nav" id="mobile-demo">
      <li><a href="/posts">Posts</a></li>
      <li><a href="#">Sign In</a></li>
      <li><a href="#">Sign up</a></li>
    </ul>
  </div>
</nav>

<%= yield %>

//= require rails-ujs

//= require materialize-sprockets

//= require_tree .

$(document).ready(function() {

$(".button-collapse").sideNav();

});

An error like this appears ㅠㅠ If you click the menu next to SNS, Sidebar needs to appear, but it's not working.

Is there a way to solve the error next to ...?

ps.

I don't think jquery is working, is that right?

I'm listening to the lecture The person who teaches is application.js.

//= require jquery

//= require jquery_ujs

//= require materialize-sprockets

//= require_tree .

It was written as... I copied the same thing, but why is the application.js different?

ruby-on-rails ruby materialize

2022-09-22 15:12

2 Answers

You can write the same in application.js. Even if you install gem, you need to add it to application.js separately.


2022-09-22 15:12

From Rails 5.1, jquery is not added by default, so you will have to set it up separately.


2022-09-22 15:12

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.