Particles.js: Working with Rails

Created on 25 Jun 2015  路  7Comments  路  Source: VincentGarreau/particles.js

Hello @VincentGarreau !

I `ve trying to use the rails gem with the material paralaxx template

I tried to add by pasting gem 'rails-assets-particles.js' in my gem file and running bundle install, but I get the error:

"Don't run Bundler as root. Bundler can ask for sudo if it is needed, and
installing your bundle as root will break this application for all non-root
users on this machine.
Fetching gem metadata from https://rubygems.org/............
Fetching version metadata from https://rubygems.org/...
Fetching dependency metadata from https://rubygems.org/..
Could not find gem 'rails-assets-particles.js (>= 0) ruby' in any of the gem
sources listed in your Gemfile or available on this machine.
pedrom@pedrom-System-Product-Name:~/code/gearcloud$ "

Am I missing something ?

All 7 comments

@JaeggerFrank
Probably it's rails-assets configuration issue, do other rails-assets gems works for you?
running bundle you should see this in output

 Fetching gem metadata from https://rails-assets.org/...
 Fetching version metadata from https://rails-assets.org/..

gem should be added in Gemfile like this

source 'https://rails-assets.org' do
  gem 'rails-assets-particles.js'
end

The gem did not work for me so here's what I did:

Using particles.js in RoR project

  1. Include app.js(if you have custom config), particles.js in assets/javascripts
  2. Include /= require particles.js in application.js
  3. Include style.css for details regarding background color/canvas
  4. Go to the view which will handle particles.js (in my case homepage which means, view/welcome/homepage) and add
<%= stylesheet_link_tag 'style'%>
<div id="particles-js"></div>
<%= javascript_include_tag 'particles', 'app'%>

Add the following to config/initializers/assets.rb

Rails.application.config.assets.precompile += %w( particles.js )
Rails.application.config.assets.precompile += %w( app.js )

To use Rails use:

/* app/assets/javascripts/application.js */
//= require particles.js.js
/* your code */
/* id in html, "path/to/json" */
particlesJS.load('id', 'assets/config.json');
<!-- app/views/controller/index.html.erb -->
<div id="id"></div>

source : README

I made an example Rails app here if anyone is interested: https://github.com/excid3/particlesjs-rails-example

@SandHilt will it wok in production environment too?? as i am calling particlesJs inside application.js

The gem doesnt work... and also all of these solutions are messy for an RoR app. You should install the npm package and call the package from the JS folder.. Webpack will precompile for you instead of sacrificing performance in assets.rb

@godiaz I can't seem to get the gem to work either...

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NoelAnnParisi picture NoelAnnParisi  路  4Comments

rahulsimpact picture rahulsimpact  路  5Comments

XRyu picture XRyu  路  6Comments

akashnimare picture akashnimare  路  7Comments

qnoox picture qnoox  路  6Comments