I integrated client side validations with rails4 using the new branches available using the following gems
gem 'simple_form', '~> 3.0.0.rc'
gem 'client_side_validations', github: "bcardarella/client_side_validations", :branch => "4-0-beta"
gem 'client_side_validations-simple_form', git: 'git://github.com/saveritemedical/client_side_validations-simple_form.git'
gem "jquery-rails"
I also added the required JavaScript as the following
//= require jquery
//= require jquery_ujs
//= require foundation
//= require rails.validations
//= require rails.validations.simple_form
//= require_tree .
//= require_self
I created this test form in order to see if it works
= simple_form_for(#post, :validate => true) do |f|
= f.error_notification
.form-inputs
= f.input :title, :required => true
.form-actions
= f.button :submit
of course in the model, it was
validates :title, presence: true
The problem is I can't figure our why it is not working, while JavaScript Console shows the following error:
Uncaught TypeError: Cannot read property 'add' of undefined
These gems involve a lot of configurations and ordering to be proper. Instead of explaining the whole procedure i can give you a link in SO where a similar problem was solved. Please do check it out and follow the same.
ruby-on-rails client_side_validation simple_form javascript error
Hope it helped !
The problem appear to be in the order of the javascript, just change the order it will work fine
Related
Nothing on the internet solved this problem.
I'm running on Rails 4.2.3 and Ruby 2.1.5
After an installation of devise, I got this error.
When I delete the line
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true % from my layout file, the error is gone and everyting looks fine.
I tried everything found on stackoverflow, didn't work.
Right now:
I use <%= link_to "sign out", destroy_user_session_path, method: :delete %> in my layout.
I tried to change the initializer : config.sign_out_via = :delete to "get" also, didn't work. Now remains "delete". Anyway it should be delete in my opinion.
My application.js file includes : //= require jquery
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Routes.rb file includes devise_for :users, path_names: {sign_in: "login", sign_out: "logout"}. If I don't add this line, it's not working also.
If I delete <%= javascript_include_tag 'application', 'data-turbolinks-track' => true % from my layout file it's working. If I don't, it's not working.
What is the problem with this javascript thing? Any opinion is welcome.
Try using the jquery-turbolinks gem and modify your application.js to look like this:
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require_tree .
//= require turbolinks
Ok the problem seems like because of Windows. The solution is adding the gemfile : 'coffee-script-source', '1.8.0' and bundle update coffee-script-source This solved.
I'm deploying a website with Heroku, though really struggling to get the jQuery firing when it goes live. Locally, all works fine.
I've had a play and haven't found any solution - it's all loading in the asset pipeline, shows as a source on the live page (albeit without working) and I've tried all of the solutions I've found on the web.
I've performed rake assets:precompile, have config.assets.compile = true and, thinking it might be a problem due to Turbolinks, installed the jquery-turbolinks gem.
With every change I thought I'd have this running, though nothing has affected the site's behaviour yet. Here's some code:
Gemfile
...
gem 'bootstrap-will_paginate'
gem 'bootstrap-sass'
# Use jquery as the JavaScript library
gem 'jquery-rails'
gem 'jquery-ui-rails'
gem 'jquery-turbolinks'
# Turbolinks makes following links in your web application faster. Read more: https://github.com/rails/turbolinks
gem 'turbolinks'
...
Application.js
...
//= require bootstrap
//= require jquery
//= require jquery.turbolinks
//= require jquery_ujs
//= require jquery-ui
//= require turbolinks
//= require_tree .
...
Application.html.erb
<head>
<link href='http://fonts.googleapis.com/css?family=Slabo+27px' rel='stylesheet' type='text/css'>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
Home.js
var validBox = function(x, y){
...
});
};
var main = function(){
$('.toggle').click(function(){
$('.about-me').toggle();
});
//Carosel
$('.arrow-next').click(function(){
...
});
$('.arrow-prev').click(function(){
...
});
//Comments
$('.btn').click(function() {
...
});
$('.status-box').keyup(validBox('.status-box', '.name-box'));
$('.name-box').keyup(validBox('.name-box', '.status-box'));
$('.btn').addClass('disabled');
}
$(document).ready(main);
Could it be a problem with the $(document).ready(main); line? I've a feeling I've read somewhere jQuery doesn't always respond as the page isn't loading from scratch / 'ready' when using Turbolinks, though thought the addition of the relevant Gem would resolve this. I've also tried $(document).on('ready', 'page:change')(main); to run the function at other points, but to no avail.
Alternatively, I seem to remember there being some command line functions to better ensure the assets run when live though can't find anything relevant.
Any help would be GREATLY appreciated as I'm stumped with this one. I'm pretty new to this, so apologies if there are any glaring, amateur errors in amongst this (though that might mean a simple solution!).
Thanks in advance, Steve.
In my case, I found the answer here:
Bootstrap won't detect jQuery 1.11.0 - Uncaught Error: Bootstrap's JavaScript requires jQuery
The Java console was throwing up the error mentioned there, and after lord knows how much hunting, simply changing the order the js files were loaded made the difference.
Bootstrap after jQuery, everything works perfectly!!
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .
I am working on a rails 4.0.1 application.
I have a a set of interactive slides, intended to teach personal finance. I have a list of question and buttons that when clicked show a jQuery Modal popup window.
My javascript files aren't loading after I perform a <%= link_to %> the next slide with Safari and Mozilla. There is no issues with Chrome.
If I reload the page, the modal does magically start working again. Here is the files that I believe are related. Any help is greatly appreciated.
application.html.erb
<%= javascript_include_tag "application", "data-turbolinks-track" => true %>
routes.rb
match '/slide1', to: 'interest_rates#slide1', via: 'get'
match '/slide2', to: 'interest_rates#slide2', via: 'get'
match '/slide3', to: 'interest_rates#slide3', via: 'get'
match '/slide4', to: 'interest_rates#slide4', via: 'get'
match '/slide5', to: 'interest_rates#slide5', via: 'get'
match '/slide6', to: 'interest_rates#slide6', via: 'get'
application.js
//= require turbolinks
//= require jquery
//= require d3.v3
//= require d3.layout
//= require rickshaw
//= require custom
//= require graph
slide1.html.erb
<%= link_to "Next", {:controller => :interest_rates, :action => :slide2}, class: "button" %>
If you haven't already, maybe check out the jquery-turbolinks gem and therubyracer gem. I've had issues where javascript wasn't loading properly, and after using the jquery-turbolinks gem, everything worked.
In my gemfile:
gem "jquery-turbolinks", "~> 2.0.1"
gem 'therubyracer', :require => 'v8'
I am unable to delete or display a confirm box in Rails 3.1.
I have the following lines in my application.hmtl.erb layout :
<%= stylesheet_link_tag "application" %>
<%= javascript_include_tag "application" %>
<%= csrf_meta_tags %>
I have also tried to change "application" to :defaults or "prototype" or "jquery" but it didn't change anything.
Need help with this !
Confirm boxes and routing to REST actions are done by the the unobtrusive javascript file. You have this problem, because you don't have it included.
Check inside your application.js if you have the following lines (before any actual javascript code):
//= require jquery
//= require jquery_ujs
This example assumes that you have the jquery-rails gem in your Gemfile. If you have prototype-rails, you should switch to:
//= require prototype
//= require prototype_ujs
I am trying to add my first bit of javascript into my rails application and so to test it in my app/assets/javascripts/users.js.coffee I added the lines:
square = (x) -> x * x
alert square(10)
When i load up the app normally and travel to a page normally using url localhost:3000, my browser does not alert me however when I travel to the page with url localhost:3000/?debug_assets=1 it does show the alert (100).
I feel as though I have not configured my rails application properly in my config file but that is just a guess.
Thanks
Asuming you have these lines in you gem file.
gem 'rails', '3.1.0'
gem 'jquery-rails'
gem 'coffee-rails', "~> 3.1.0"
You'll should have this line in your /app/views/layout.html.erb file
<%= javascript_include_tag "application" %>
and this in your /app/assets/javascript/application.js file
//= require jquery
//= require jquery_ujs
//= require_tree .
or
//= require jquery
//= require jquery_ujs
//= require users
finally in the /app/assets/javascript/users.js.coffee
jQuery ->
square = (x) -> x * x
alert square(10)
Good luck!
There may be a bug in your javascript that is only coming up when all your javascript is dumped into a single file. Have you looked in your javascript console for any errors? It's possible these don't come up when you run in debug mode.