Open samerawada92 opened 4 years ago
Requiring the CSS isn't a problem, just add the following line to your application.css file:
*= require social-share-button
However, I couldn't find a way to import the JS files. I tried to add require("social-share-button")
in the javascript/application.js file but I get the following error:
Error: Cannot find module 'social-share-button'
Yes, same issue here.
Requiring the CSS isn't a problem, just add the following line to your application.css file:
*= require social-share-button
However, I couldn't find a way to import the JS files. I tried to add
require("social-share-button")
in the javascript/application.js file but I get the following error:Error: Cannot find module 'social-share-button'
I guess this gem is not maintained?
@nicolrx did you find a workaround?
@nicolrx did you find a workaround?
I did my own setup with font-awesome icons ;)
https://github.com/ruby-china/homeland/blob/master/app/assets/stylesheets/application.scss#L4
Rails 6 use case
This is for the .scss file What about importing the JS files when using webpack in rails 6?
Here's the solution for rails 6
@samerawada92 @ja-meel
run rails webpacker:install:erb
, it will generate a hello_erb.js.erb
in javascript/pack folder, you can easily change it into social-share-button.js.erb
edit social-share-button.js.erb
and copy paste the following line.
import "<%= File.join(Gem.loaded_specs['social-share-button'].full_gem_path, 'app', 'assets', 'javascripts', 'social-share-button.coffee') %>"
run rails webpacker:install:coffee
, it will also generate a hello_coffee.coffee
file which you can delete or ignore it.
edit application.js
file under app/javascript/packs
, add the following line
require('packs/social-share-button.js.erb')
restart rails server, then it should work.
Here's the solution for rails 6
@samerawada92 @ja-meel
- run
rails webpacker:install:erb
, it will generate ahello_erb.js.erb
in javascript/pack folder, you can easily change it intosocial-share-button.js.erb
- edit
social-share-button.js.erb
and copy paste the following line.import "<%= File.join(Gem.loaded_specs['social-share-button'].full_gem_path, 'app', 'assets', 'javascripts', 'social-share-button.coffee') %>"
- run
rails webpacker:install:coffee
, it will also generate ahello_coffee.coffee
file which you can delete or ignore it.- restart rails server, then it should work.
Thanks. Following this I ended with the error Uncaught ReferenceError: SocialShareButton is not defined at HTMLAnchorElement.onclick
when clicking Share button
Any idea what could be wrong?
Here's the solution for rails 6 @samerawada92 @ja-meel
- run
rails webpacker:install:erb
, it will generate ahello_erb.js.erb
in javascript/pack folder, you can easily change it intosocial-share-button.js.erb
- edit
social-share-button.js.erb
and copy paste the following line.import "<%= File.join(Gem.loaded_specs['social-share-button'].full_gem_path, 'app', 'assets', 'javascripts', 'social-share-button.coffee') %>"
- run
rails webpacker:install:coffee
, it will also generate ahello_coffee.coffee
file which you can delete or ignore it.- restart rails server, then it should work.
Thanks. Following this I ended with the error
Uncaught ReferenceError: SocialShareButton is not defined at HTMLAnchorElement.onclick
when clicking Share buttonAny idea what could be wrong?
edit application.js
file under app/javascript/packs
, add the following line
require('packs/social-share-button.js.erb')
I'm having an issue getting the css working. JS works fine after following the steps above. https://github.com/ruby-china/homeland/blob/master/app/assets/stylesheets/application.scss#L4 doesn't exist anymore. I've tried with the usual *= require social-share-button but i'm using Rails 6. Thanks
I found this which might help someone https://github.com/Bunlong/rails-social-share-button/blob/master/app/assets/stylesheets/rails-social-share-button.css.erb
Here's the solution for rails 6
@samerawada92 @ja-meel
- run
rails webpacker:install:erb
, it will generate ahello_erb.js.erb
in javascript/pack folder, you can easily change it intosocial-share-button.js.erb
- edit
social-share-button.js.erb
and copy paste the following line.import "<%= File.join(Gem.loaded_specs['social-share-button'].full_gem_path, 'app', 'assets', 'javascripts', 'social-share-button.coffee') %>"
- run
rails webpacker:install:coffee
, it will also generate ahello_coffee.coffee
file which you can delete or ignore it.- edit
application.js
file underapp/javascript/packs
, add the following linerequire('packs/social-share-button.js.erb')
- restart rails server, then it should work.
First, thanks for the above solution, it really helped :)
One more thing nevertheless, it doesn't work with coffee-loader
v2.0.0.
If any trouble, use this gem version in your Gemfile
:
"coffee-loader": "^1.0.1",
Here's the solution for rails 6 @samerawada92 @ja-meel
- run
rails webpacker:install:erb
, it will generate ahello_erb.js.erb
in javascript/pack folder, you can easily change it intosocial-share-button.js.erb
- edit
social-share-button.js.erb
and copy paste the following line.import "<%= File.join(Gem.loaded_specs['social-share-button'].full_gem_path, 'app', 'assets', 'javascripts', 'social-share-button.coffee') %>"
- run
rails webpacker:install:coffee
, it will also generate ahello_coffee.coffee
file which you can delete or ignore it.- edit
application.js
file underapp/javascript/packs
, add the following linerequire('packs/social-share-button.js.erb')
- restart rails server, then it should work.
First, thanks for the above solution, it really helped :) One more thing nevertheless, it doesn't work with
coffee-loader
v2.0.0. If any trouble, use this gem version in yourGemfile
:"coffee-loader": "^1.0.1",
Could not find gem 'coffee-loader (>= 1.0.1)' in any of the gem sources listed in your Gemfile.
Here's the solution for rails 6 @samerawada92 @ja-meel
- run
rails webpacker:install:erb
, it will generate ahello_erb.js.erb
in javascript/pack folder, you can easily change it intosocial-share-button.js.erb
- edit
social-share-button.js.erb
and copy paste the following line.import "<%= File.join(Gem.loaded_specs['social-share-button'].full_gem_path, 'app', 'assets', 'javascripts', 'social-share-button.coffee') %>"
- run
rails webpacker:install:coffee
, it will also generate ahello_coffee.coffee
file which you can delete or ignore it.- edit
application.js
file underapp/javascript/packs
, add the following linerequire('packs/social-share-button.js.erb')
- restart rails server, then it should work.
First, thanks for the above solution, it really helped :) One more thing nevertheless, it doesn't work with
coffee-loader
v2.0.0. If any trouble, use this gem version in yourGemfile
:"coffee-loader": "^1.0.1",
Could not find gem 'coffee-loader (>= 1.0.1)' in any of the gem sources listed in your Gemfile.
Just change the version in your Gemfile and rebundle 🤔
@martintsan help me
I found this which might help someone https://github.com/Bunlong/rails-social-share-button/blob/master/app/assets/stylesheets/rails-social-share-button.css.erb
This is for the wrong gem
How is this issue closed with no solution?
Any documentation on the setup of this gem on a rails 6 application? Mainly requiring the CSS/JS files.