serviceworker-rails | Use Service Worker with the Rails asset pipeline | Web Framework library
kandi X-RAY | serviceworker-rails Summary
kandi X-RAY | serviceworker-rails Summary
Use Service Worker with the Rails asset pipeline
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Runs the block .
- Initialize a Rack middleware .
- Get the handler for a given handler .
- Resolve handler
- Returns the route handler for the given route .
- Matches an asset against the given path .
- Returns the middleware for the middleware .
- Tries to respond to a rack response .
- Matches the path for a Rack environment .
- Returns the request headers .
serviceworker-rails Key Features
serviceworker-rails Examples and Code Snippets
Community Discussions
Trending Discussions on serviceworker-rails
QUESTION
I saw a lot of similar questions here, but nothing of provided advises has helped. Every time I run cap production deploy
I got error:
ANSWER
Answered 2020-Oct-21 at 15:11How I solved it:
- Go to server command line
- As we can see in error log, the last command before error appears was:
Command: cd /home/deploy/project/releases/20201018151933 && ( export RAILS_ENV="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.5" ; RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.6.5 $HOME/.rbenv/shims/bundle exec bundle check )
So we go to our folder:
cd /home/deploy/project/releases/20201018151933
and run there command:
export RAILS_ENV="production" RBENV_ROOT="$HOME/.rbenv" RBENV_VERSION="2.6.5" ; RBENV_ROOT=$HOME/.rbenv RBENV_VERSION=2.6.5 $HOME/.rbenv/shims/bundle exec bundle check
After that we see same error:
Could not find concurrent-ruby-1.1.7 in any of the sources. Run 'bundle install' to install missing gems.
- In same folder run
bundle install
and after gem installed we can out of server command line. - Run
cap production deploy
and everything is gonna be fine.
I still don't know what is the root problem of this error, and how to fix it permanently, but this works for me. I hope it will be useful for anyone else.
QUESTION
I have a form_tag using Ajax to save a new user card with Stripe. It renders a Stripe card form, passes the input to a controller method, and then is supposed to serve a js file. It works without the Stripe stuff, but with it, I'm getting authentication issues.
Here's the basic code:
...ANSWER
Answered 2020-Feb-20 at 22:54Keep everything as it was, and just update .submit()
The actual issue is sending as HTML
instead of as JS
on form.submit()
.
QUESTION
I am trying to set up a web push app, with one signal notifications. I know nothing about service workers, but used rails service-workers gem. I get this error >importScripts is not defined. I have already followed this tutorial from rossta, serviceworker-rails. The error must be in OneSignalSDKWorker.js.erb.
I have already tried to change the name to OneSignalSDKWorker.js nothing seems to work. I'm working fully https on Heroku. make a function
...ANSWER
Answered 2019-Sep-18 at 01:41I can see a couple potential issues.
1) If you are attempting to importScripts
from a service worker, that needs to be executed at the top of the file and not in a method. In other words, it needs to be the first thing that runs within your service worker.
2) You are attempting to register multiple services workers which works but only if they are defined for different scopes. In the code you provided, you are registering them for the same scope which will only register one of them.
QUESTION
I am using the webpacker
gem (version 4.0.7) for a Rails 6 RC2 app, and I am also using serviceworker-rails
middleware gem (version 0.6.0) to integrate Service Worker with Rails.
Now, I want to create a serviceworker.js
pack file (which I copied over and modified from serviceworker-rails
README file) so that it can be served by Webpack and be routed using serviceworker-rails
middleware.
So, in app/javascript/packs/serviceworker.js.erb
(with erb-loader
installed), I did this:
ANSWER
Answered 2019-Aug-13 at 08:43So, after digging deep for so long, I found the solution from this issue on GitHub (and also realized that I didn't read and understand the error properly as the error was undefined method 'asset_pack_path'
and has nothing to do with compilation whatsoever). The problem was fixed by simply doing:
QUESTION
I am using the serviceworker-rails gem to make my eCommerce application a progressive web app. Here is a gem file snippet from the project;
...ANSWER
Answered 2018-Sep-23 at 03:47I finally got it to work :) . The gem supplying the application layout is solidus but the problem is that the manifest is in the local application within which solidus is a gem.
To make it visible to the gem; I removed the tags from
QUESTION
I've got a Rails application that is using webpacker to serve the styles and the javascript. I'm using serviceworker-rails
gem to have a service worker.
Externally from the service worker installation I need to add the cache the css and js produced by webpack. How can i achieve this?
I've tried serving the file with the asset pipeline an using the webpacker helpers but when it's compiled I get:
...ANSWER
Answered 2018-Feb-26 at 15:06Accessing webpacker helpers in a file that will be part of applicaition.js produced by webpack is impossible (change my mind if you know how to do it)
Instead I've used the asset pipeline to serve this file and inside use:
<%= Webpacker.manifest.lookup 'application.css' %>
to get the application styles, and will return something like:
/packs/application-d85a17a26660e00c18a4d4f9535ee7d7.css
The same applies for application.js
QUESTION
right now i'm using push notification from this library https://github.com/rossta/serviceworker-rails
I have followed the instructions and i have success implemented it, (i got the push notification). But now, i'm wondering whether is it possible for user to push notification without subscribe ? Because i wanted my push notification is sent after people register on my sign up form, and only admin who can subscribe & get push notification from new user registration.
This is my script when a new user visit and sign up for the first time
...ANSWER
Answered 2017-Oct-27 at 05:24You can send push notification from admin side using curl
function. I did push notification recently using java script and PHP. You can send same as ruby on rails. Please refer firebase.google.com. You will get better idea.
Using firebase three files is needed to send push notification. FIrst html/php/ruby file for allow user to accept permission. Second Service worker file upload in the root folder. Third server file need to send push notification for the individual token or group token. When user allows the notification you will get a token. You can save the token in the database and send the push notification.
Html,
QUESTION
I'm getting an error while pushing to production...
...ANSWER
Answered 2017-May-12 at 09:37Based on the second half of that note: "or replace require_tree with something more explicit." the issue should be solvable by removing //= require serviceworker-companion
from the tree.
You can acomplish that by adding an exception to the tree in the following way:
(In aplication.js
)
After
QUESTION
How can we make the browser notification icon
and body
dynamically customized based upon the @challenge.image
and the @challenge.description
?
I got the notification to pop up by clicking webpush-button
, but only the title
of the message is dynamically changing. How can I make it work for body
and icon
too?
challenges/show.html.erb
...ANSWER
Answered 2017-Apr-26 at 12:31The event.data
object in the self.addEventListener("push", (event)=> {...})
, has a method json()
, that method convert to json the event.data
value.
This will works only if the sended data is in the proper json format.
Here is an example how I'm using web push:
QUESTION
As soon as a person comes to my site they are confronted with...
But I only want that popup to occur after a user clicks "Push" so that the user may understand the context of the request.
How to only trigger the browser notification request upon a user clicking "Push"?
I implemented push via serviceworker gem, webpush gem, VAPID tutorial.
...ANSWER
Answered 2017-Apr-26 at 11:13Just Wrap your notification asking part from application.js with function. Then add that function to click handlers of Push button.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install serviceworker-rails
After bundling the gem in your Rails project, run the generator from the root of your Rails project.
config/initializers/serviceworker.rb - for configuring your Rails app
app/assets/javascripts/serviceworker.js.erb - a blank Service Worker script with some example strategies
app/assets/javascripts/serviceworker-companion.js - a snippet of JavaScript necessary to register your Service Worker in the browser
app/assets/javascripts/manifest.json.erb - a starter web app manifest pointing to some default app icons provided by the gem
public/offline.html - a starter offline page
Adds a sprockets directive to application.js to require serviceworker-companion.js
Adds serviceworker.js and manifest.json to the list of compiled assets in config/initializers/assets.rb
Injects tags into the head of app/views/layouts/application.html.erb for linking to the web app manifest
Let's add a ServiceWorker to cache some of your JavaScript and CSS assets. We'll assume you already have a Rails application using the asset pipeline built on Sprockets.
The page requests a service worker at /serviceworker.js
The Rails app responds to the request by compiling and rendering the file in app/assets/javascripts/serviceworker.js.erb.
The console displays messages from the page and the service worker
The application JavaScript and CSS assets are added to the browser's request/response Cache.
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page