0

I used this command to install gems for my rails project and I added following in application.js

require jquery-ui
require jquery-colorpicker

This gave error:

could not find file 'jquery-colorpicker'

this is the code for items/new.js.erb

$('#dialog h3').html("<i class='glyphicon glyphicon-plus'></i> Add New Item");
$('.modal-body').html('<%= j render("form") %>');
$('#dialog').modal("show");
$('#dialog').on('shown.bs.modal', function () {
#   $('.colorpicker').focus()
    $('.colorpicker').colorpicker {autoOpen:true, hideOn:'button'}
})
anujeet
  • 167
  • 2
  • 14
  • did you use a gem for `jquery-colorpicker` ? where/how did you install it? – shivam Dec 15 '15 at 07:46
  • I used this command to install gem "gem install jquery-colorpicker-rails" when i added require statement for it in application.js i got the mentioned error – anujeet Dec 15 '15 at 07:47
  • what is *this* command? – shivam Dec 15 '15 at 07:47
  • if `https://github.com/Ferroman/jquery-colorpicker-rails` is the gem you installed, then you need to `require jquery.ui.all` and `require jquery.colorpicker` (think README is missing the "r" there), like the README says – dinjas Dec 15 '15 at 08:13
  • @dinjas this is for Rails version <4 I'm using Rails version >4 and for it i changed require jquery.ui.all to require jquery-ui and i don't know what will be the substitution for jquery.colorpicker – anujeet Dec 15 '15 at 08:31

2 Answers2

1

Add following to your Gemfile:

gem 'jquery-ui-rails'
gem 'jquery-colorpicker-rails'

Add following to application.js

//= require jquery-ui
//= require jquery-colorpicker

Hope, this helps!

Also, there is another gem jquery-minicolors-rails which embeds the jQuery colorpicker in the Rails asset pipeline. See: https://github.com/kostia/jquery-minicolors-rails

Veets
  • 171
  • 6
  • hey Thanks! can you tell me a way how i can use it on my input field? – anujeet Dec 15 '15 at 09:56
  • I never used the gem `jquery-colorpicker-rails`. But I have used the gem `jquery-minicolors-rails`. Here is the documentation on how to use it: https://github.com/kostia/jquery-minicolors-rails#usage – Veets Dec 15 '15 at 10:45
  • Tried out `jquery-colorpicker-rails` just now. You text_field should look something like: `<%= f.text_field :pickcolor, class: 'colorpicker' %>` and the relevant coffee script should look something like: `$ -> $('.colorpicker').colorpicker {autoOpen:true, hideOn:'button'}`. You can further add more options listed at: https://github.com/vanderlee/colorpicker/#colorpickeroptions – Veets Dec 15 '15 at 11:05
  • jquery-minicolors-rails , I followed the documentation. Put the js code in my items.coffee file. But it is still not working, any idea? but the input filed on which I'm applying the function is in modal popup , will it make any difference? – anujeet Dec 15 '15 at 11:09
  • I have added the code for new.js.erb I'm getting error "Uncaught SyntaxError: Unexpected token $" what could be the reason for it? – anujeet Dec 15 '15 at 12:39
  • It shouldn't make a difference even if you are using a modal popup as long as the relevant js is loaded properly. Re: "Uncaught SyntaxError: Unexpected token $" please see http://stackoverflow.com/questions/8081701/i-keep-getting-uncaught-syntaxerror-unexpected-token-o#answer-8081745 – Veets Dec 16 '15 at 09:25
0

You need to include the gem itself into the gemfile.

Using gem install colorpicker will only install it on your local machine.

cccvandermeer
  • 317
  • 2
  • 14