Ask A Question

Notifications

You’re not receiving notifications from this thread.

jquery_ujs and rails-ujs problem ajax page

pikooli asked in Rails

hello everyone.

i am new in rails and ruby , i just started like 1 week ago .

i trying to do a chat between 2 people on rails, with jquery for the ajax part.

everything work, but i got this error that i don't undestand and it really bother me

image to the error (coun't include it with a image balise)
https://ibb.co/KKjKLPf

VM17:2082 Uncaught Error: If you load both jquery_ujs and rails-ujs, use rails-ujs only.

i undestand that i use jquery_ujs and rails-ujs in the same time , and rails want me to only use rails-ujs

my main page have this as code

<h1>welcome to the chat  </h1>
<div id='conv'>
    <div id='message'>
    </div>
    <div id='sendmsg'>
    <%= form_tag "/", method: "post" do %>
        <input type='hidden' name='name' value='phil'/>
        <input id='tex' type="text" name="message" />
        <input id='sen' type="submit" value="send" />
    <% end %>
</div>
</div>

my javascript is like this

window.addEventListener('load', function () {
    setInterval(refreshMessage,3000);
    function refreshMessage(){
        $.ajax({
            type: 'GET',
            url: '/chatBoard',
            success: function(data){
                $('#message').html(data);
            },
            error : function(){
                $('#message').html('error');
            } 
        })
    };
});

this ajax send to the server a GET to '/chatBoard' and it will return all message in the database with this script.

<% @messages.each do |message| %>
<%= message.name %> :
<%= message.message %>

<% end %>

i try to find a solution , but i am still stuck so i post it here , i would like to make this work but without this error ?
what should i do ? change my ajax request with a coffescript one ? haven't learn coffescript yet :/

thanks in advance.

Reply

Hello , i fixe it by commenting the application.js file and remove the rails/ujs :)

code still work , i think it work with the jquery_ujs thought

// require("@rails/ujs").start()
require("turbolinks").start()
require("@rails/activestorage").start()
require("channels")
require("custom")
Reply
Join the discussion
Create an account Log in

Want to stay up-to-date with Ruby on Rails?

Join 87,563+ developers who get early access to new tutorials, screencasts, articles, and more.

    We care about the protection of your data. Read our Privacy Policy.