Questions tagged [rails-ujs]
48 questions
41
votes
5 answers
Using Rails-UJS in JS modules (Rails 6 with webpacker)
i just switched to Rails 6 (6.0.0.rc1) which uses the Webpacker gem by default for Javascript assets together with Rails-UJS. I want to use Rails UJS in some of my modules in order to submit forms from a function with:
const form =…

R4ttlesnake
- 1,661
- 3
- 18
- 28
13
votes
3 answers
Rails UJS not firing with Rails 7
I upgraded my Rails application to Rails 7. I know that Turbolinks and Rails UJS actually are replaced by the Hotwire combination of Stimulus and Turbo in Rails 7, but I wanted to know whether I can still use UJS and if yes, why is it not…

sam
- 191
- 1
- 8
5
votes
2 answers
Rails 6: link to destroy_user_session_path using GET instead of DELETE
I have just started a simple Rails 6.0.3.1 project.
I'm setting up the Devise actions, but the logout link doesn't seem to work. It's performing a GET request instead of a DELETE despite the fact that I specify the method:
- if user_signed_in?
=…

DaniG2k
- 4,772
- 36
- 77
5
votes
3 answers
Migrating Rails from Asset Pipeline to Webpacker: Uncaught ReferenceError: $ is not defined in rails-ujs.js
I am migrating from using the asset pipeline to webpacker in Rails 5.2. My AJAX responses are all causing Uncaught ReferenceError: $ is not defined in rails-ujs.js errors in the browser console.
I have setup my webpacker environment to include…

TheRealNeil
- 233
- 2
- 9
4
votes
1 answer
@rails-ujs How to intercept ajax:complete
In a Rails 6.1 application using @rails/ujs (no jquery), I'm trying to intercept when ajax requests are fired and when they are completed.
I have added the following to my application.js
document.addEventListener("turbolinks:load", () => {
…

Sig
- 5,476
- 10
- 49
- 89
4
votes
2 answers
Rails 5.2: Rails UJS, Turbolinks and CSP
We recently upgraded our Application to Rails 5.2. We are also using Turbolinks (together with the Rails Engine) and RailsUJS.
With Rails 5.2 we have new DSL for CSP (Content security policy). It is configured like this in…

Spa
- 473
- 4
- 10
3
votes
0 answers
Using global Rails-UJS in TS modules (Rails with webpacker)
I'm trying to use Rails from @rails/ujs in webpacker ts-loader similar to Rails in the asset pipeline. I want a global variable Rails available in all modules.
For now, I can circumvent the problem by importing it in each module, but, for the sake…

RWDJ
- 734
- 8
- 13
2
votes
1 answer
Rails `link_to` with `method` parameter gives 404 when open in new tab
Using Ruby 2.5.1/Rails 5.2.4.1 I generated a new Rails app, and edited/created the following files:
# config/routes.rb
Rails.application.routes.draw do
root 'some#home'
post 'foo' => 'some#foo'
end
# app/controllers/some_controller.rb
class…

Bob Whitelock
- 167
- 3
- 12
2
votes
1 answer
Rails 6: Rails not defined
I am trying to fire a form submit using UJS:
<%= f.file_field :profile_image,
direct_upload: true,
accept: 'image/png,image/gif,image/jpeg',
onchange: "Rails.fire(this.form, 'submit')"
…

user3574603
- 3,364
- 3
- 24
- 59
2
votes
3 answers
Cannot find module '@rails/ujs' - Rails 6 Webpack App
I have these errors in a Rails 6 app and all javascript is not working:
ERROR in ./app/javascript/packs/application.js
Module not found: Error: Can't resolve '@rails/activestorage' in '/Users/jrsahuquillo/Dropbox/myappname/app/javascript/packs'
@…

Sahu
- 183
- 2
- 9
2
votes
1 answer
ActiveAdmin breaks Rails JQuery UJS. Unobtrusive JavaScript ajax:success and ajax:error are not firing or being called
I have the following
=form_for @issue, remote: true, html: {class: 'form-inline'} do |f|
...
And

Chloe
- 25,162
- 40
- 190
- 357
2
votes
1 answer
Rails.ajax call returning false (rails-ujs)
I'm trying using ajax with rails-ujs but my call doesn't doing nothing. The application use the rails 5.1 and have the rails-ujs require in application.js
When i test the code in a browser console, it is return false.
Bellow is the code:
…

Léo Rocha
- 324
- 3
- 13
2
votes
0 answers
After moving from `jquery_ujs` to `rails-ujs`, why are jquery objects not initialized in tests?
After migrating from jquery_ujs to rails-ujs, certain JS tests are failing and proving very difficult to debug.
The problem appears to be that Jquery objects are only initialized for the first test in a sequence. Everything works fine in my…

Andy Harvey
- 12,333
- 17
- 93
- 185
2
votes
0 answers
How to re-initialize rails-ujs
I have a view within my Rails app which includes a link:
= link_to 'abc', abc_url, remote: true
This link on its own works as intended.
But I embedded it in the drawer component of the mdc library.
Now the link appears to be working like a regular…

heroxav
- 1,387
- 1
- 22
- 65
2
votes
1 answer
couldn't find file 'rails-ujs' with type 'application/javascript' (On page load)
Created a Rails 5 app using devise for auth and attempting to add Thredded gem for forums.
Expected behavior
The app should load at http://localhost:3000.
Actual behavior
After server starts, the following message shows up in the chrome browser…

Timothy
- 139
- 1
- 12