How to use datepicker in rails without gem? - ruby-on-rails

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

Related

Chartkick gem, trying to create a pie chart

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

Bootstrap Gem Installation Issue

I have added the bootstrap-sass gem and have installed the bundle. I have gone to github and think I have followed the directions correctly to finish the install for ruby on rails. It doesn't appear to be making a difference however on my local site - no font/formatting changes have been made, even after the install.
I am using a PC, https://github.com/findingtheway/pin
Change your app/views/layouts/application.html.erb to this:
<head>
<title>Pin</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
Rails uses application by default you have default which is why bootstrap is not loading.

chartkick why is x-axis a date

I've created a custom hash but the x-axis is showing up as a date. I want it to just show the value in the hash (1,2,3 etc...). This is my first time using chartkick so I'm lost as to why this is happening.
What's being displayed is January 1, 2000 with the value of 504, February 1, 2000 with value of 499, March 1 etc....
When I set #chart_hash as an array, instead of a hash (which is what is shown below), I get times in the x-axis instead of dates.
application.html.erb
<head>
<title>SampleApp</title>
<%= javascript_include_tag "//www.google.com/jsapi", "chartkick" %>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
_chart.html.erb
<%= line_chart #chart_hash %>
#chart_hash
{0=>504, 1=>499, 2=>499, 3=>504, 4=>509, 5=>514, 6=>514, 7=>521.5, 8=>516, 9=>511, 10=>511, 11=>511, 12=>506, 13=>501, 14=>501, 15=>506, 16=>511, 17=>516, 18=>511, 19=>518.5, 20=>522.5}
Answer: In the past chartkick could only use date objects, but now if you pass the discrete option it will use regular numbers.
_chart.html.erb
<%= line_chart #chart_hash, discrete: true %>

ruby-on-rails client_side_validation simple_form javascript error

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

No route matches assets

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') %>

Resources