I am facing below issue while Onclick method in html.erb
file in ruby on rails.
Uncaught ReferenceError: modifyGroup is not defined at HTMLButtonElement.onclick (new:48141)
I have written a search and other methods in js file which all are working fine. But this method only not I am getting this error.
function modifyGroup() {
var groupname = document.getElementById("groupname").value;
var parametersname=document.getElementById("object_test").value;
$.ajax({
method: "GET",
dataType: "text",
url: "/group/update_group",
data: {
groupname: groupname,
parametersname: parametersname,
},
success: function(result) {
if(result === 'false') {
alert('Group Could not be Updated !!!');
return false;
} else{
alert('Group Updated successfully !!!');
window.location='/group/new';
}
}
});
}
Please include the js files in your views by using the
<%= javascript_include_tag "filename_js", "data-turbolinks-track" => true %>
and please add your js file in assets.rb
Rails.application.config.assets.precompile += %w( filename_js.js )
Then run
rake assets:precompile
And start your rails server
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.