Select2-rails is not working with ActiveAdmin - ruby-on-rails

I have difficulties integrating select2-rails with ActiveAdmin. I followed setup steps on
Select2-rails Github page: https://github.com/argerim/select2-rails and I added line:
//= require select2
to app/assets/javascripts/application.js and line:
*= require select2
to app/assets/stylesheets/application.css
so I assume when I have page in ActiveAdmin I should be able to add line:
$('#add_student_select').select2()
to active_admin.js.coffee
But its not working. In console I can see following error:
Uncaught TypeError: undefined is not a function
(anonymous function)
fire
self.fireWith
jQuery.extend.ready
completed
I also followed this StackOverflow question which recommends to add this line to active_admin.css.scss:
body.active_admin {
#import "select2";
}
But then I get following error:
File to import not found or unreadable: select2.
Do I integrate it correctly? I don't think that ActiveAdmin is able to get even access to the librabry.

If you're adding Select2 to the ActiveAdmin interface, you must add the javascript and styles to the ActiveAdmin assets:
# app/assets/javascripts/active_admin.js.coffee
#
#= require select2
#
# ...
And the stylesheets:
// app/assets/stylesheets/active_admin.css.scss
//
//= require select2
//
// ...
In the example you provided, Select2 would be available to the main Rails application, but not ActiveAdmin. ActiveAdmin uses its own javascript and stylesheet files.

I had met the same issue making select2 work with activeadmin, but instead I used a gem named activeadmin-select2. I had installed it according to the README, but I still got error "File to import not found or unreadable: select2.". It seems like that select2-rails had not been installed or not be accessible, however. So then I tried to add select2-rails to my Gemfile, and bundle, lastly, everything went well. You should checked your gem loading before you can make it work.

Related

#= require not working after upgrade to Rails 5

I upgraded Rails 4.2.10 application to Rails 5. Solved errors with bundling and some deprecations. I am able to start the Rails Application, but when I try to load the Application, it fails with error, Invalid CSS after "#": expected id name, was "= require in the css file
I tried using #import, but it fails for external files in vendor/assets. Nevertheless, I want to understand why it isnt working anymore. In my config, I have the file in config.assets.precompile +=
In my index.html.erb,
<%= stylesheet_link_tag 'users' %>
In users.scss,
#= require "dashboard/dx"
Note: I am using sass-rails in my Gemfile
The error that I get,
Sass::SyntaxError in Dashboard::Users#index
Invalid CSS after "#": expected id name, was "= require "dash..."
Extracted source (around line #1):
#= require "dashboard/dx"
Hey I think the error is throwing because in your typical .scss file you would have to use either an #import "dashboard/dx" and#= requiremight only work in.css`
The problem with this line
#= require "dashboard/dx"
This syntax is not working with .scss file. Either You have to write like this
#import 'dashboard/dx'
Or rename the file with .css extension.
Note: You can also try to rename with .css.scss extension May be it works also sometimes.

Chartkick on Heroku ReferenceError: Can't find variable: Chartkick?

I'm using chart kick in a standard way, like how the GitHub instructions dictate and it works in a local version. When uploaded to Heroku my charts produce an error "ReferenceError: Can't find variable: Chartkick" on the rendered partial page.
this is what I've done so far.
gemfile:
gem 'chartkick'
application.js:
//= require Chart.bundle
//= require chartkick
//= require_tree .
my show view renders a partial that calls a controller action via path method.
my controller action:
def event_names
#applet = RegisteredApplication.find(params[:id])
render json: #applet.events.group(:name).count
end
my partial that calls the action:
<%= pie_chart event_names_registered_application_path %>
I'm thinking the reason I'm getting the "ReferenceError: Can't find variable: Chartkick?" is because of the asset pipeline. But I don't fully understand what i can do to solve it is. please help :D
Just ran into the same issue. Make sure that application.js gets loaded before the Chart in your view. See details

Rails 4.0. vendor/assets/javascripts - Asset Pipeline issue

I am running Rails 4.0.1 and Ruby 2.0.0. I currently have a graph.js that takes inputs in from the user for a savings calculator in order to create a graph with d3 and the rickshaw.js graph.
My graph.js file is saved in the app/assets/javascripts/graph.js. I make a call to the Rickshaw graph with
var graph = new Rickshaw.Graph()
I am getting an error of Uncaught ReferenceError: Rickshaw is not defined.
The rickshaw.js file is saved in vendor/javascript/rickshaw.js along with d3.layout.js and d3.vs.js. If I save all of these files in the app/assets/javascripts everything works fine, but that does not seem to be the correct rails way.
Does anyone know how to fix this error?
Thank you.
To use the asset pipeline, you'll want just the filename in the require statements:
// Vendor Files
//= require d3.v3
//= require d3.layout
//= require rickshaw
See the asset pipeline docs for more info on asset organization.

Rails Admin: add javascript library to custom action

I'm building a custom action for rails admin that includes a custom view.
I want to include a local copy of sparkline.js but I can't figure out a way to do this.
I tried to add the sparkline.js to the /vendor/assets/javascripts/actions/action_name directory but it is not loaded by rails admin
Is there any other way to get this file loaded
I did this by putting the external library into the app/assets/javascripts/rails_admin/custom directory and adding a 'require' statement to the rails_admin ui.js file.
i.e.
// in app/assets/javascripts/rails_admin/custom/ui.js
//= require ./sparkline.js
You can do this with coffeescript too:
# in app/assets/javascripts/rails_admin/custom/ui.js.coffee
#= require ./sparkline.js

is it possible to replace MarkerClusterer with MarkerClustererPlus in the gem ‘gmaps4rails’?

I would like to continue using the gem ‘gmaps4rails’ but use MarkerClustererPlus instead of MarkClusterer ... is this possible ?
Since the syntax seems to be the same, you should only disable the auto inclusion of the js files:
<%= gmaps( data_hash, true)
Then add these files yourself in your page and include the MarkerClustererPlus instead of the drfault one.
In your Gemfile, add this line:
gem 'markerclustererplus-rails'
You can include it by adding the following to your javascript file:
//= require markerclusterer
reference - https://github.com/RogerE/markerclustererplus-rails

Resources