Add autocomplete to the navigation bar in Rails Project - ruby-on-rails

I'm running a Rails project which consists of Navgation bar on all the pages. I also have a input tag on the nav bar for searching purpose, but how to implement autocomplete in the particular search bar.
I tried using rails-jquery-autocomplete and implemented the way it asked but unfortunately it didn't worked for me. No search result are visible on screen or on console
brands_controller.rb
class Admin::BrandsController < Admin::AdminController
autocomplete :brand, :name
end
routes.rb
resources :brands, param: :uuid do
get :autocomplete_brand_name, :on => :collection
end
_navigationbar.html.erb
<form class="navbar-form pull-left" role="search">
<div class="form-group">
<input type="text" class="form-control search-bar" placeholder="Type here for search..." data-autocomplete="<%=autocomplete_brand_name_admin_brands_path%>">
</div>
</form>
Gemfile
gem 'rails', '~> 5.0.0'
gem 'rails-jquery-autocomplete'
gem 'jquery-rails'
application.js
//= require jquery
//= require jquery_ujs
//= require moltran/modernizr.min
//= require moltran/bootstrap.min
//= require tagsinput/jquery.tagsinput.min.js
//= require autocomplete-rails
Generated HTML:
<div class="form-group">
<input type="text" class="form-control search-bar" placeholder="Type here for search..." data-autocomplete="/admin/brands/autocomplete_brand_name">
</div>

You are missing //= require jquery-ui/autocomplete in application.js. Update application.js to
//= require jquery
//= require jquery_ujs
//= require moltran/modernizr.min
//= require moltran/bootstrap.min
//= require tagsinput/jquery.tagsinput.min.js
//= require jquery-ui/autocomplete
//= require autocomplete-rails
In your gemfile add
gem 'jquery-ui-rails'
Also replace input tag with
<%=autocomplete_field_tag 'search', '', autocomplete_brand_name_admin_brands_path %>

Related

Why bootstrap modal can't display on Rails 5?

1.code of index.html.erb:
<%= link_to 'Add release', new_release_articles_path, {:remote => true, 'data-toggle' => "modal", 'data-target' => '#modal-window'} %>
<div id="modal-window" class="modal hide fade" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true"></div>
<p>Hoc javascript</p>
code of controller:
def new_release
respond_to do |format|
format.html
format.js
end
end
code of new_release.js.erb
$('#modal-window').html("<%= j render 'blorgh/articles/new_release'%>");
$('#modal-window').modal();
code of new_release.html.erb
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h3 id="myModalLabel">Modal header</h3>
</div>
<div class="modal-body">
**here comes whatever you want to show!**
</div>
<div class="modal-footer">
<button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
<button class="btn btn-primary">Save changes</button>
</div>
application.js
//= require rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
Result click link add release:
Look at this
//= require rails-ujs
//= require jquery
//= require bootstrap
//= require jquery_ujs
//= require turbolinks
//= require_tree .
You don't need rails-ujs if you use jquery_ujs so you can remove this //= require rails-ujs from here and follow the order
//= require jquery
//= require jquery_ujs
//= require bootstrap
//= require turbolinks
//= require_tree .
you can consider one rails-ujs or jquery_ujs, after changing this restart the server
Update from comment
Use tabindex="-1" to div modal window

Bootstrap-select not expanding

I am facing problems with dropdown of selectpicker. I am not able to get the dropdown menu when i click on .
Following are my files:
View:
<div class="form-group set-up-down">
<%= f.label :pricing_style_id %><br>
<%= f.select 'pricing_style_id', options_from_collection_for_select(#labs_pricing_style, :id, :name),{:include_blank => '-Choose Starting Price Sheet-'},class:'selectpicker'%>
<p id="pricingstyleError" style="display: none; color: red;">Please enter a pricing style for this new pricesheet.</p>
</div>
application.js:
//= require jquery
//= require jquery_ujs
//= require jquery.turbolinks
//= require bootstrap-colorpicker.min
//= require bootstrap-datetimepicker.min
//= require bootstrap-select.min
//= require bootstrap-switch
//= require bootstrap-switch.min
//= require bootstrap-tagsinput
//= require bootstrap
//= require jquery-1.12.1.min
// require_tree .
application.css:
*= require_tree .
*= require_self
Any help will be appreciated. thank you in advance.

Owl Carousel Slider won't Display in Ruby on Rails App

I've been trying to implement the OwlCarousel image slider into my RoR app. The problem is that the slider doesn't seem to be called upon.
This is what it currently outputs (with two images) -
This is my current relevant code -
In application.js
//= require jquery
//= require bootstrap-sprockets
//= require jquery_ujs
//= require turbolinks
//= require owl.carousel
//= require_tree .
In application.css.scss
/*
*= require owl.carousel
*= require owl.theme
*= require_tree .
*= require_self
*/
#import "bootstrap-sprockets";
#import "bootstrap";
In show.html.erb
<div>
<div class="col-xs-12 col-md-offset-2 col-md-6 project-right-panel">
<div id="owl-carousel">
<% #post_attachments.each do |p| %>
<%= image_tag p.avatar_url %>
<%= link_to "Edit Attachment", edit_post_attachment_path(p) %>
<% end %>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#owl-carousel").owlCarousel({
autoPlay: 3000,
item : 3,
itemsDesktop : [1119,3],
itemsDesktopSmall : [979, 3]
});
});
</script>
item : 3 should be items: 3. That might be it. Their demo also looks like they want you to wrap your images in a div with class item.

Rails 4 - JQuery Datepicker not displaying in production

I am using JQuery-UI to display the datepicker on a simple rails form. In my local development environment it works as expected, but when I deploy to the production environment it will not display.
Gem File includes:
gem 'rails', '4.0.3'
gem 'sass', '~> 3.2.5'
gem 'bootstrap-sass', '~> 3.3.3'
gem 'sass-rails', '4.0.1'
gem 'sprockets', '2.11.0'
em 'jquery-rails', '3.1.0'
gem 'jquery-ui-rails', '5.0.3'
gem 'turbolinks', '1.1.1'
My application.js
//= require jsapi
//= require chartkick
//= require jquery
//= require jquery_ujs
//= require jquery-ui/datepicker
//= require bootstrap-sprockets
//= require holder
//= require jquery.dataTables.min
//= require dataTables.bootstrap
//= require highcharts.js
//= require_tree .
My application.scss
#import "bootstrap-sprockets";
#import "bootstrap";
#import "partials/*";
#import "customer/*";
#import "jquery-ui/datepicker";
The form contains:
<div class="row">
<label class="control-label col-xs-3">Start Date :</label>
<div class="col-xs-2">
<%= f.input :start_date, :as => :datepicker, :label => false %>
</div>
</div>
<div class="row"><label class="control-label col-xs-3">End Date :</label>
<div class="col-xs-2">
<%= f.input :complete_date, :as => :datepicker, :label => false %>
</div>
</div>
I have a dates.js.coffee file as follows:
$ ->
$("input.datepicker").each (i) ->
$(this).datepicker
altFormat: "yy-mm-dd"
dateFormat: "dd/mm/yy"
altField: $(this).next()
Any help would be fantastic...
Thanks to japed for pointing me in the right direction. I was inadvertently loading a JS file (gruntfile.js) via the asset pipeline that was not loading correctly and causing the rest of the JS to not load. I removed this file and all is working as expected.

bootstrap date picker rails not working

read = ->
$('#date_picker').datepicker
$(document).ready read
$(document).on "page:load", read
This the code I am using the above is how I call the datepicker. I am using date picker rails gem. The below is the form code
= simple_form_for :due_on,:url=> admin_requests_path,:method => "get",html: {id: "due_on_filter"} do |f|
= f.input :mydate,:disabled => 'disable', :input_html => { :data => {:behaviour => :datepicker },id: "date_picker"}
I am not able to get it to work. There are no errors but datepicker just does not work.
This is my application.js
//= require jquery
//= require jquery_ujs
//= require turbolinks
//= require bootstrap
//= require jquery.ui.core
//= require jquery_nested_form
//= require dataTables/jquery.dataTables
//= require dataTables/jquery.dataTables.bootstrap3
//= require datatable_calls
//= require nprogress
//= require nprogress-turbolinks
//= require chosen-jquery
//= require chosen_calls
//= require filter_ajax_calls
//= require bootstrap-datepicker/core
//= require custom
HTML raw output of the form is:
<form accept-charset="UTF-8" action="/admin/requests" class="simple_form due_on" id="due_on_filter" method="get" novalidate="novalidate">
<div style="display:none"><input name="utf8" type="hidden" value="✓" /></div>
<div class="control-group string required due_on_mydate">
<label class="string required control-label" for="date_picker">
<abbr title="required">*</abbr> Mydate</label>
<div class="controls">
<input class="string required" data-behaviour="datepicker" id="date_picker" name="due_on[mydate]" type="text" />
</div>
</div>
</form>
you sure this js/coffee code works?
Could you try that please:
setInterval(function() {
$(function () {
var datepicker = $('#date_picker');
if(datepicker.length) {
datepicker.datepicker();
alert("found the element!");
} else {
alert("could not find element");
}
});
}, 4000);
Edit in your script as
$(function(){$("#datepicker").datepicker({
showbuttonPanel: true
});
});
and you need to require bootstrap and jquery-ui-1.10.4.custom files in both js & css application. Now implement the datepicker where ever you want using the datepicker id.

Resources