huacnlee / social-share-button

Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...
MIT License
582 stars 309 forks source link

Install documentation for Rails 6 #189

Open samerawada92 opened 4 years ago

samerawada92 commented 4 years ago

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

nicolrx commented 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'

samerawada92 commented 4 years ago

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 commented 4 years ago

I guess this gem is not maintained?

samerawada92 commented 4 years ago

@nicolrx did you find a workaround?

huacnlee commented 4 years ago

https://github.com/ruby-china/homeland/blob/master/app/assets/stylesheets/application.scss#L4

Rails 6 use case

nicolrx commented 4 years ago

@nicolrx did you find a workaround?

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

ja-meel commented 4 years ago

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 commented 4 years ago

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

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

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

basharabdullah commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 4 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 3 years ago

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 commented 2 years ago

@martintsan help me

benlieb commented 1 year ago

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

benlieb commented 1 year ago

How is this issue closed with no solution?