I attempted to integrate the Sweet Alert 2 java-script library for customising standard alert boxes into a Rails 7 application, but I received the following error message: "Swal is not defined."
I'm using Ruby 3 and Rails 7.
I initially attempted to use the "sweet-alert2-rails" gem in my Rails application, but there are no current updates available. I therefore attempted to accomplish this using import map, and I did so by running the following line.
bin/importmap pin sweetalert2
On top of that, I added the lines below to the application.js
import Swal from "sweetalert2"
I encountered the aforementioned problem when attempting to use "Sweet Alert 2" in my view files.
Swal.fire(
'Good job!',
'You clicked the button!',
'success'
)
To integrate Sweet Alerts into my Rails application, I used these links.
https://sweetalert2.github.io/
https://github.com/sweetalert2/sweetalert2
You defined Swal in application.js using import Swal from "sweetalert2", and then you are trying to use it in your view files, so it is saying that Swal is not defined.
Previously, in rails 6, we added "sweet alert" using "yarn install," and the same error occurred. Hence, to solve this error either in Rails 6 or in Rails 7, you need to add the following line inside your application.js.
import Swal from 'sweetalert2';
window.Swal = Swal;
Adding window.Swal will undoubtedly fix your problem in Rails 7.
You can find references on my blog and in my GitHub repository. I have written this article for Rails 7.0.4 and Ruby 3.1.0. and also implemented the code for the same version.
Blog : https://rutikkpatel.medium.com/sweet-alert-2-in-ruby-on-rails-7-3f4cffe1ea5f
GitHub Repository : https://github.com/rutikkpatel/Sweet-Alert-Rails
I hope that will help you with your issue.
Related
I have a Ruby on Rails single page application using React as the front-end, and since we upgraded from Rails 6.1 to Rails 7.0, the warning "DEPRECATION: action_cable.js has been renamed to actioncable.js – please update your reference before Rails 8" appears on the browser console in almost every page of the application, except for static views (without forms or such) such as e-mails and the home page.Warning on the browser console
I've tried reviewing my Gemfile to make sure they are up-to-date, ran bundle update hoping that the problem was caused by an outdated gem, but the warning is still there. I've checked the project folder, and there is no "action_cable.js" or "actioncable.js" file, nor are there any references to those files/paths in any part of the code.
Does anybody have an idea on how to fix this warning? I couldn't find any information on how to do it, or other people that are having the same issue.
This is my first time posting here, so if there's any information missing, I'll be more than happy to share it!
I'm trying to make the bootsy gem work with Rails 4.
Followed the requirements without installing imageMagick. I just need the editor to show but nothing is working yet.
I also got this inspecting my browser since the bootsy tags work on the form but don't show anything.
Uncaught TypeError: Cannot read property 'locale' of undefined
Can anyone help? Thanks!
The gem's documentation clearly states in requirements:
https://github.com/volmer/bootsy
ImageMagick or GraphicsMagick (for MiniMagick)
Rails 4
Bootstrap 3 fully installed in your app.
Make sure you've installed these correctly. Other than that, without seeing any of your code, we can only guess at solutions. Please post code if you can.
I'm working my way through Dan Kehoe's book 2 and everything was going well until I tried to run the Zurb Foundation example. Using Foundation 5 I get the error ".column" failed to #extend ".small-6".
The selector ".small-6" was not found.
Use "#extend .small-6 !optional" if the extend should be able to fail.
It seems as though I have not loaded something which defines the foundation css entities, but I am flumoxed as a complete newbie in ror. Any help would be greatly appreciated here. I've back tracked using git and tried it again, but I get the same thing. Thanks.
Frank
I had the same problem and modifying the Gemfile.lock solved the problem.
Specifically, I changed the version of foundation-rails, which was 6. etc to (5.5.3.2), resulting in foundation-rails (5.5.3.2).
This was the same version as specified in the GitHub repository of the author.
https://github.com/RailsApps/learn-rails/blob/master/Gemfile.lock (line61)
Hope it helps!
Okay, so I am new to Ruby, let alone Ruby on Rails. I am using this online IDE called Cloud9 and or other wise known as C9. Anyways once you generate all your files you are given a Coffeescript file. I used this code, however it is not working. I have already installed the package through the node manager. However, when I used the console.log method for testing it did work.
I'm following Vic Ramon's tutorial. I tried to use the latest version of Rails and Ember-source and I get the following error when visiting home page:
After clicking on link next to error I get this:
How can I fix that?
I ran the following commands:
rails g ember:bootstrap -n App --javascript-engine coffee
rails g ember:install
I removed turbolinks. I also created home controller and an empty view for home#index. Root is set to home#index. Also created following view file:
// app/assets/javascripts/templates/application.js.emblem
h1 Hello World
outlet
Ember gems im using:
Using emblem-source 0.3.18
Using ember-data-source 1.0.0.beta.14.1
Using ember-rails 0.16.1
Using emblem-rails 0.2.2
This could be due to some version incompatibilities between your versions of ember-related gems, as there were quite substantial changes in recent versions of ember (e.g. introduction of HTMLBars, etc.)
Your best bet is to clone the original repo and then try to upgrade individual gems and check if it still works after each upgrade. This way you will be able to identify the troubling gem.
I have verified that the original repo code indeed works with the versions of gems in its current Gemfile.lock.
If you are starting a new Rails + Ember app, ember-cli-rails is probably the way to go, giving you the best of both worlds.
Emblem was the culprit. Replacing .emblem with .handlebars fixed the problem. I tried the tip from emblem-rails git page and icluded
gem "emblem-source", github: "machty/emblem.js"
but that didn't change anything.
I also followed this tutorial (alongside a few others) and I encountered several issues alongside the way ranging from handling templates to setting up the JSON API. I don't see your entire source code so I cannot pinpoint the exact problem. However, it seems that we have similar projects, so you can compare your code to my blog project source code and see what is causing these issues. Comparing to Ramon's tutorial, my blog has implemented everything until chapter 15.
https://github.com/Deovandski/Fakktion/tree/Ember-Rails
If you are a beginner like myself, then I recommend avoiding CoffeeScript and Emblem and sticking to Javascript as much as possible for the first months because you will find more resources and examples. Also, let me know if you need assistance in setting up the project as I used .gitignore to hide things like secrets.yml