Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Install documentation for Rails 6 #189

Open
samerawada92 opened this issue Mar 31, 2020 · 18 comments
Open

Install documentation for Rails 6 #189

samerawada92 opened this issue Mar 31, 2020 · 18 comments

Comments

@samerawada92
Copy link

samerawada92 commented Mar 31, 2020

Any documentation on the setup of this gem on a rails 6 application? Mainly requiring the CSS/JS files.

@nicolrx
Copy link

nicolrx commented Apr 2, 2020

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'

@samerawada92
Copy link
Author

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'

@samerawada92
Copy link
Author

I guess this gem is not maintained?

@samerawada92
Copy link
Author

@nicolrx did you find a workaround?

@huacnlee
Copy link
Owner

@nicolrx
Copy link

nicolrx commented Apr 15, 2020

@nicolrx did you find a workaround?

I did my own setup with font-awesome icons ;)

@ja-meel
Copy link

ja-meel commented May 7, 2020

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?

@martintsan
Copy link

martintsan commented May 28, 2020

Here's the solution for rails 6

@samerawada92 @ja-meel

  1. 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

  2. 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') %>"
  1. run rails webpacker:install:coffee, it will also generate a hello_coffee.coffee file which you can delete or ignore it.

  2. edit application.js file under app/javascript/packs, add the following line

require('packs/social-share-button.js.erb')
  1. restart rails server, then it should work.

@basharabdullah
Copy link

Here's the solution for rails 6

@samerawada92 @ja-meel

  1. 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
  2. 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') %>"
  1. run rails webpacker:install:coffee, it will also generate a hello_coffee.coffee file which you can delete or ignore it.
  2. 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?

@martintsan
Copy link

martintsan commented Jun 11, 2020

Here's the solution for rails 6
@samerawada92 @ja-meel

  1. 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
  2. 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') %>"
  1. run rails webpacker:install:coffee, it will also generate a hello_coffee.coffee file which you can delete or ignore it.
  2. 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?

edit application.js file under app/javascript/packs, add the following line

require('packs/social-share-button.js.erb')

@tomdringer
Copy link

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

@tomdringer
Copy link

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

@yannklein
Copy link

Here's the solution for rails 6

@samerawada92 @ja-meel

  1. 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
  2. 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') %>"
  1. run rails webpacker:install:coffee, it will also generate a hello_coffee.coffee file which you can delete or ignore it.
  2. edit application.js file under app/javascript/packs, add the following line
require('packs/social-share-button.js.erb')
  1. 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",

@certilremy
Copy link

Here's the solution for rails 6
@samerawada92 @ja-meel

  1. 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
  2. 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') %>"
  1. run rails webpacker:install:coffee, it will also generate a hello_coffee.coffee file which you can delete or ignore it.
  2. edit application.js file under app/javascript/packs, add the following line
require('packs/social-share-button.js.erb')
  1. 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",

Could not find gem 'coffee-loader (>= 1.0.1)' in any of the gem sources
listed in your Gemfile.

@yannklein
Copy link

Here's the solution for rails 6
@samerawada92 @ja-meel

  1. 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
  2. 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') %>"
  1. run rails webpacker:install:coffee, it will also generate a hello_coffee.coffee file which you can delete or ignore it.
  2. edit application.js file under app/javascript/packs, add the following line
require('packs/social-share-button.js.erb')
  1. 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",

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 🤔

@ninhnv-1216
Copy link

@martintsan help me

@benlieb
Copy link

benlieb commented Oct 7, 2022

@benlieb
Copy link

benlieb commented Oct 7, 2022

How is this issue closed with no solution?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests