Ruby on Rails application and trying to add client_side_validation working and getting two javascript runtime errors when visiting the screen fields.
The errors;
Uncaught TypeError: Cannot call method 'add' of undefined
Uncaught TypeError: Cannot call method 'remove' of undefined
The Gemfile
source 'https://rubygems.org'
........
gem 'simple_form'
gem 'client_side_validations'
gem 'client_side_validations-simple_form'
.....
The application.html.erb
<!DOCTYPE html>
<html>
<head>
<title><%= content_for?(:title) ? yield(:title) : "Drill Investor" %></title>
<!--[if lt IE 9]><script src="http://html5shim.googlecode.com/svn/trunk/html5.js" type="text/javascript"></script><![endif]-->
<%= stylesheet_link_tag "application", :media => "all" %>
<%= javascript_include_tag "application", "rails.validations"%>
<%= csrf_meta_tags %>
</head>
<body>
...
The View - _form.html.erb
<%= simple_form_for (#basin), :validate => true do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.association :country %>
<%= f.input :name %>
</div>
....
The Model
class Basin < ActiveRecord::Base
include ActiveModel::ForbiddenAttributesProtection
belongs_to :country
has_many :drills
validates :country_id, :name, presence: true
validates :name, uniqueness: {scope: [:country_id],
message: "A country can only have one basin with this name"}
end
config/environments/development
added
config.assets.precompile += %w( rails.validations.js )
and pre-compiled the code
in config/initializers/simple_form set config.browser_validations = true
in config/initializers/client_side_validations
added
require 'client_side_validations/simple_form' if defined?(::SimpleForm)
The error
When visiting the Basins page and selecting a Country from the drop down menu select (f.association :country), when I tab to the next field using web browser Chrome and Developers - Java Script Tools
Uncaught TypeError Cannot call method 'removed' of undefined
This occurs in generated code - app/assets/javascripts/rails.validations.js
about line 175 in module
window.ClientSideValidations.enablers
I have tried many things to correct this error including changing the include order for app/assets/javascript, re-running the pre-compile, changing the app view, change config.assets.compile = false to true (set back to false now),
Would greatly appreciate any help
thanks
Pierre Le Count
You also need to add rails.validations.simple_form after rails.validations. You could either add as follows:
<%= javascript_include_tag "application", "rails.validations", "rails.validations.simple_form" %>
Or,
In app/assets/javascripts/application.js:
//= require rails.validations
//= require rails.validations.simple_form
Then change javascript_include_tag to following in app/views/layouts/application.html.erb:
<%= javascript_include_tag "application" %>
Related
I have tried with gem datepicker, but i have to use datepicker without any gem of datepicker?
i have added datepicker js files like
bootstrap-datepicker.ja.js
bootstrap-datepicker.js
this file i have loaded in view(erb)
<%= javascript_include_tag 'locales/bootstrap-datepicker.ja.js', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'bootstrap-datepicker.js', 'data-turbolinks-track' => true %>
but it's not working giving error like
in console:
ActionView::Template::Error (bootstrap-datepicker.js):
error on page:
Sprockets::Rails::Helper::AssetNotPrecompiled in MUser#index
bootstrap-datepicker.js
Check if you have jquery included, otherwise you cannot use bootstrap.
try adding <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> in your view above the other two scripts.
So your code should look something like this:
<script src="http://code.jquery.com/jquery-1.9.1.min.js"></script>
<%= javascript_include_tag 'locales/bootstrap-datepicker.ja.js', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'bootstrap-datepicker.js', 'data-turbolinks-track' => true %>
You could also have a look at <%= form.date_field :date_attribute %> - it will use a native date picker, supported by all major browsers.
See https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/date
<%= form.date_field :date, attribute: 'date' %>
where the :date is your model
I'm new to rails and trying to link main.css.scss to index.html.erb file in views/main.
My css file is located in app/assets/stylesheets. This is default, I did not change anything.
So in my index.html.erb file I added the following:
<%= stylesheet_link_tag "main" %>
This throwed an error which advised me to include ".css" at the end of "main". I added ".css" and ".css.scss" to the end of main. The main page loads, but without the css file.
What is the correct way to link css in rails 5?
Read the api docs here. It will help you to understand how you can link css in rails.
Also take a look at Samuel's answer. He explained it really well.
It's very simple. If you don't want to use default application.css and application.js, then create new files, like in your case main:
app/assets/stylesheets/main.scss
app/assets/javascripts/main.js
Then in your layout include those files:
<!DOCTYPE html>
<html>
<head>
<title>Foobar</title>
<%= stylesheet_link_tag 'main', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'main', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
And add those files to assets.rb:
Rails.application.config.assets.precompile += %w( main.scss main.js)
And restart the server.
I just installed the gem "chartkick" to my gemfile and copyied and pasted some code just to get the project started, this is what I used in my view.
<%= pie_chart({"Football" => 10, "Basketball" => 5}) %>
I also included
<%= javascript_include_tag "path/to/highcharts.js", "chartkick" %>
So that is not the issue but I keep getting this error
Any ideas on what I'm doing wrong?
Try this, After installing the "chartkick" gem,
replace this javascript include tag
<%= javascript_include_tag "path/to/highcharts.js", "chartkick" %>
with this
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
Whenever I try to upload a file with Carrierwave + s3 on my Heroku app I get this error "We're sorry, but something went wrong.", looking into my log I see this error:
2012-08-20T21:18:56+00:00 app[web.1]: Started GET "/assets/" for 24.90.124.181 at 2012-08-20 21:18:56 +00002012-08-20T21:18:56+00:00 app[web.1]:2012-08-20T21:18:56+00:00 app[web.1]: ActionController::RoutingError (No route matches [GET] "/assets"):
I've did everything in this tutorial to deploy my app to Heroku on the Cedar stack, but I still see that error. I also had to add this to my application.html
<%= javascript_include_tag :defaults %> <%= javascript_include_tag "jquery" %> <%= javascript_include_tag "nested_form"%> <%= javascript_include_tag "application"%>
because having <%= javascript_include_tag "application" %> only loaded "application.js"
I've tried everything I come across trying to get my uploader to work, but I don't know what the problem is. Everything works perfectly on my local app.
This is my app on github
My Heroku app
you can easyly replace the
<%= javascript_include_tag :defaults %>
<%= javascript_include_tag "jquery" %>
<%= javascript_include_tag "nested_form"%>
<%= javascript_include_tag "application"%>
with: <%= javascript_include_tag "application" %> if your application.js file do this imports.
the default imports are:
//= require jquery
//= require jquery_ujs
//= require_tree .
if the problem is a missing javascript this should fix it
Other problem i see was this link inside app/views/deals/show.html.erb:
<%= image_tag(#deal.user.logo, :class => 'company_logo') %>
this line is returning this html:
<img alt="Assets" class="company_logo" src="/assets/">
this img src is invalid, and that is the error your are receiving on log.
if this image tag could link to an image path, like /assets/avatar.png i believe your problem will be fixed
Since you are using Carrierwave, you need to do the following:
<%= image_tag(#deal.user.logo.url, :class => 'company_logo') %>
or
<%= image_tag(#deal.user.logo.current_path, :class => 'company_logo') %>
I'm building an app in Rails. I'm using e text editor. I'm running windows. Just basic link_to with embedded ruby.
On all my links in every major browser, the link path is showing in brackets beside the anchor text.
<%= link_to "Sign Up Now", signup_path %>
Resulting output is:
Sign Up Now (/signup)
I think you are using blueprint. Try to fix print.css file, comment:
a:link:after, a:visited:after {content:" (" attr(href) ")";font-size:90%;}
I had this problem and it was because fixed it by removing a line looking like:
<%= stylesheet_link_tag "application", :media => "all" %>
As mentioned above, the link path appears in brackets due to the following CSS lines inside blueprint:
In blueprint/print.css
a:link:after, a:visited:after {content:" ("attr(href)")";font-size:90%;}
and in blueprint/src/print.css
a:link:after, a:visited:after {
content: " (" attr(href) ")";
font-size: 90%; }
Instead of removing those lines or commenting them out, I would recommend adding the media attribute while declaring the print.css stylesheet as follows:
<%= stylesheet_link_tag 'blueprint/print', :media => 'print' %>
By doing so the styles are rendered only while printing the document and not on the screen.
There is more information about the media attribute here.
While referring to the other css files within blueprint, you should specify the media attribute as follows:
<%= stylesheet_link_tag 'blueprint/screen', :media => 'screen' %>
<%= stylesheet_link_tag 'blueprint/plugins/fancy-type/screen', :media => 'screen' %>
<\!--[if lt IE 8]>
<%= stylesheet_link_tag 'blueprint/ie', :media => 'screen' %>
<\![endif]-->
<\!--[if lt IE 7]>
<%= stylesheet_link_tag 'basic_ie.css', :media => 'screen' %>
<\![endif]-->