pikooli

Joined

750 Experience
0 Lessons Completed
1 Question Solved

Activity

Posted in jquery_ujs and rails-ujs problem ajax page

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")

Posted in jquery_ujs and rails-ujs problem ajax page

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.

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.