Using three.js in Rails the right way

I've looked everywhere for a solution to this problem, but unfortunately haven't found anything helpful.

Currently, I'm in the process of creating a new Ruby on Rails application and I want to start practicing using three.js. To check if it was properly required, I tried using my browser console, only to receive the error: ReferenceError: THREE is not defined

After reading through this post: Most efficient way to get a Three.js project to work in a ruby on rails app?, I expected to see some results.

I attempted adding the three.js file to the assets/javascripts folder and also used the threejs-rails gem from here: https://github.com/marvindanig/threejs-rails, but none of these solutions worked.

I made sure to require it in the asset pipeline in the application.js file:

//
//= require three
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .

If anyone has any suggestions on what steps I should take next, please let me know. It seems like the main issue right now is that it's not being required correctly.

EDITED: Problem resolved. It turns out I was inheriting from the wrong controller model.

Answer №1

To integrate the Three.js file into your project, simply place it in the assets/javascript folder. In your application.js file, ensure that you have "//= require_tree ." at the end to make sure everything functions properly. It is important to delete the "//= require three" line as Rails automatically loads this file and loading anything before jquery and turbolinks may cause issues with loading. If you do want to explicitly add the Three.js file to your project, include it just before "//=require_tree ."

Answer №2

a.) Add your three.js script to the following directory:

"app/assets/javascripts/three.js"

b.) In the application.js file, include this line: #= require three

Ensure that the server is running, then refresh the webpage and open the web console (F12). Type in Three and check for a return result to confirm it's set up correctly.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

How can I delay the execution of "onAuthStateChanged" until "currentUser.updateProfile" has completed?

Currently facing an issue with registering users in my Vue app. When a user registers, I need to trigger the updateProfile function to add more user data. However, the problem arises when the onAuthStateChanged function in my main.js is executed before the ...

Challenges encountered in configuring system tests with Capybara and Selenium on a Rails 5.1 application (recently migrated from Rails 4)

I am currently in the process of setting up system tests using Capybara and Selenium for a Rails 5.1 application that was previously upgraded from Rails 4. Here is a summary of what I have accomplished so far. In the Gemfile within group :development, :te ...

What is the limitation in transmitting data as a JavaScript object rather than a JSON object?

As a newcomer to expressjs, I recently developed an application using it. Interestingly, when I send data in JSON format through POSTMAN, the application successfully returns the data. However, when I try to send data as a JavaScript object in the request ...

Performing calculations in Javascript using input and span elements

<input type="number" name="quantity" id="quantity"> <span id="price">4000</span> <input type="text" value="" id="total" readonly> <input type="button" value="calculate Total Price" onClick="calculate()"> I have a form with f ...

The functionality of the vue2-timepicker package seems to be malfunctioning in vue.js

I am utilizing the vue2-timepicker JavaScript package. npm install vue2-timepicker --save Following that, I import the CSS and datetimepicker component file from node_modules into my main.js file // import the CSS file import 'vue2-timepicker/dist ...

Why is the console log not working on a library that has been imported into a different React component?

Within my 'some-library' project, I added a console.log("message from some library") statement in the 'some-component.js' file. However, when I import 'some-component' from 'some-library' after running uglifyjs with ...

What's up with the Chrome Dev Tools Error Log?

I am having an issue with debugging JavaScript files using breakpoints in Chrome Dev Tools. Whenever an error occurs, a red error message flashes on the screen so quickly that I can't read what it says. Is there a way to change this setting or access ...

Discover the elements with Protractor, cycle through the total number of located elements, and proceed to press the button

Trying to figure out how to click a button multiple times based on the number of elements found with a specific classname. If there are 3 elements found, the button should be clicked 3 times. The current approach: (Update at the bottom) The total count ...

Can Sync blocking IO be implemented solely in JavaScript (Node.js) without the use of C code?

Is JavaScript intentionally designed to discourage or disallow synchronous blocking I/O? What is the reason for the absence of a sleep API in JavaScript? Does it relate to the previous point? Can browsers support more than one thread executing JavaScript? ...

Mastering JavaScript: Techniques for Selecting Multiple Values in a Dropdown Menu

I have a code that works perfectly, but the issue arises when I click on the add button and a new select option is added with a value instead of an id. How can I pass the Id to option.value = array[i]; ? var array = ["PACKING & LOADING","BAG GODOWN", ...

How to make an Ajax "POST" request to the server using jQuery or AngularJS without sending any parameter data

"Execute a 'POST' request to the server by using the code provided below However, the parameter data is not being sent to the server. I have attempted both the jQuery Way and var request = $.ajax({ url: baseUrl, type:'post', da ...

Missing transitive dependencies have been identified within the node_modules directory when using npm

In my software development journey, I am working on two npm projects - one called X and the other called Y. Let's say that X relies on angular and has it specified as a dependency in its package.json file. To establish a connection between X and Y, I ...

How can Reactjs access a configuration file?

I am struggling to find a solution for reading a properties file in reactJS. I have come across the "properties-reader" module but I can't figure out how to make the require function work. Is there an easier way? For instance, import React, { Com ...

Is it recommended to utilize CDN in Vue.js for optimal performance?

Currently facing a version compatibility issue between leaflet and leaflet-draw in my vuejs project. In light of this, I am seeking alternative solutions for map function editing such as adding polylines, copy and paste functions, and more. While I did com ...

What is the best way to retrieve the value of a v-select field when submitting a form?

I've been struggling to retrieve the value of a select field in my Vue project. Despite trying various methods, some of which I still have references for, I haven't succeeded yet. Here are a couple of links I've used: CodePen - Select Fiel ...

Wait for the asynchronous method to finish before displaying the page

My question is similar to this one:stop angular-ui-router navigation until promise is resolved Despite exploring various answers, none have successfully addressed my issue. In my application, a cookie containing a token is stored. Upon page load (such as ...

What are some effective ways to slow down the image transitions in a Javascript slideshow?

I am currently developing a slideshow that updates Images, Title, and Description simultaneously based on their Array index. The slideshow is functional BUT, my goal is to achieve a smooth transition to the next/previous Image (... title & descript ...

Using the v-for directive before applying the Vue directive

I need help with displaying images in a carousel from data fetched via Firebase. I have created a directive, but the problem lies with the v-for loop. The directive is executed before the v-for loop, resulting in no items in the carousel. Directive: di ...

Which is better for scrolling in Angular 2+: using HostListener or window.pageYOffset?

Which syntax is best for maximizing performance in Angular 2+? Is it necessary to use HostListener, or is it simpler to obtain the scroll position using the onscroll window event and pageYOffset? @HostListener('window:scroll', ['$event&ap ...

Troubleshooting MaterialUI Datatable in Reactjs: How to Fix the Refresh Issue

Currently, I am facing an issue with rendering a DataTable component. The problem is that when I click on the "Users" button, it should display a table of Users, and when I click on the "Devices" button, it should show a table of Devices. But inexplicably, ...