How do I tell my Rails app where my CasperJS script is? - ruby-on-rails

I want to launch several CasperJS scripts from within my Ruby on Rails app.
I want to know two things:
Where should I place the script? (which folder)
Do I need to tell Ruby on Rails where CasperJS can be found within my system? If so, how?

If its not a gem, and your using Rails 3.x and up, just place it in
/app/assets/javascripts
if the
require_tree.
in the application.js is there it would automagically include everything in the above folder.
If here are issues about the order of inclusion, write
//= require xxxxxxx
xxxxxxx being the js file name without the extension
and it will be included in top to bottom order.

Related

Sencha Architect generated layout can't integrate to Ruby on Rails Project

I'm actually working in a Ruby on Rails Project and I've created a simple layout with Sencha Architect and the files Sencha Architect generates are:
and Inside of app folder :
So I have in my Ruby on Rails project this code for the layout, in te lines 15 and 16 I have already referred to the files that were generated by sencha architect
And when I run the project the browser console displays this error:
it can't find the app/view/MainView.js wich indeed is in that rout. Can someone help me?
Javascript needs to go in app/assets/javascripts. Just placing the file in app/view doesn't make it available at that "route", this is not how Rails works. You're working with an application, not a static web site serving up all the files in the various directories.
Look into Rails Routing, and the Asset Pipeline for more information.
If you put MainView.js into app/assets/javascripts, you can include it in the application.js file, like the other files that are likely there, or if not, like this:
//= require ./MainView # brings in this one file
or
//= require_directory . # brings in all javascripts in the directory
And now when you bring in the application javascript, your MainView content will also be included.

Where can i find the chosen.jquery.js file in my rails app?

I'm guessing this is a silly question, but i'm a bit of a newb...
I've added the chosen gem to my rails app by adding it to my Gemfile and requiring chosen-jquery in my application.js file.
My question is: where can i find the actual javascript file for chosen? Is it downloading it automatically?
Simply include the JS and CSS files like described in the documentation on the main page of the Github project and it will be included when precompiling your assets. The files are not within your project directory but rather within the gem and will be resolved by the pipeline when the gem is included.
If you need to get to the file directly (for modifications), you need to put the JS in there manually. You can then still include it in the main application.js for the pipeline and have better control of the version in use. To me, this is the preferred method.
However, may I suggest switching to Select2 which is originally based on Chosen but under much more active development and better documentation:
http://ivaynberg.github.io/select2/
https://github.com/ivaynberg/select2
There's also a gem for it if you like:
https://github.com/argerim/select2-rails
It's in a gem itself. If you look at vendor/assets/javascripts in gem root, you'll see all javascripts that come with chosen gem. They are added by assets pipeline, with
//= require chosen-jquery
line in your application.js.
Look up your assets load path. Like this:
in terminal cd to your app root
then open rails console
then run Rails.application.config.assets.paths
Your chosen-jquery is in one of those folders.

How to use soundmanager2 wilth rails?

I have installed soundmanager2 within my rails application as a plug in.
after installation, I tried following command to use sound manager
rails generate sound_manager2
it shows generator not found error :(
Experimenting with rails 3 but actually wants to use with rails 2 and ruby 1.8.6
Anybody know, how it works under rails ? or is there any other way to play sound with rails app ?
Manually add the following SoundManager2 files to vendor/assets/javascripts/soundmanager2:
soundmanager2-nodebug-jsmin.js (or one of the other scripts, depending on your needs)
soundmanager2.swf
soundmanager2_debug.swf
soundmanager2_flash9.swf
soundmanager2_flash9_debug.swf
And then you should have either //= require tree . or //= require soundmanager2/soundmanager2-nodebug-jsmin in your application's JavaScript manifest file (app/assets/javascripts/application.js).
Or alternatively, just use the soundmanager-rails gem. I haven't used it myself, so I can't vouch for whether it works.
You can just drop the JavaScript and / or Flash files from the soundmanager2 download into your rails app, the plugin is just a JavaScript wrapper, you don't need it at all.
Then follow the offical Getting started guide

How to edit twitter bootstrap files in rails?

I'm trying to find the twitter-bootstrap files in my rails app ('bootstrap-sass', '2.0.0'), as I need to make a change directly to the bootstrap-responsive.css file, however, I can't find it.
I have bootstrap up and running, but can't seem to find the bootstrap files. How do I locate the bootstrap-responsive.css file?
Thank you!
The bootstap-sass gem uses the Rails 3.2 asset pipeline to inject the necessary stylesheets into your app. The actual stylesheet files are located in the gem installation directory, not in your project itself.
Depending on what you want to change, you can either:
Copy the _bootstrap-responsive.scss file from the gem into your app/assets directory and edit it there.
Customize the necessary Bootstrap variables before loading up Bootstrap in your application.scss file:
$btnPrimaryBackground: #f00;
#import "bootstrap";
Edit: Try looking under
app/assets/stylesheets
Here's an example
https://github.com/joliss/solitr/tree/master/app/assets/stylesheets
I'm not too familiar with the structure of rails apps but did you create a local copy or are you using the bootstrap files being hosted directly by github? You should be able to figure that out by checking one of your launched html pages and viewing the source, looking for something like
<link rel="stylesheet" href="http://twitter.github.com/bootstrap/1.3.0/bootstrap.min.css">
If it's a local page, there should be a directory somewhere in your rails app where the files are stored - perhaps there's a 'static' folder or something similar? Try file-searching for it, good chance you might find it.
(I use Django/Python for web projects but I'll look into Rails a bit and see if I find anything)

Rails 3.1 asset pipeline: Ignore backup files from Emacs and other editors

In a Rails 3.1 project, if I edit app/assets/javascripts/users.js.coffee using Emacs, then Emacs creates a backup file named app/assets/javascripts/users.js.coffee~ (note the trailing "~").
Unfortunately, the new Rails 3.1 asset pipeline sees this .coffee~ file, and injects it directly into the generated application.js, which in turn causes JavaScript errors in the browser.
I could turn off backups in Emacs by writing:
(setq backup-directory-alist nil)
...or I could use:
(setq backup-directory-alist `(("." . "~/.emacs-backups")))
...to move them into another directory.
But this would require every Emacs user on the project to reconfigure their Emacs, which is undesirable. I would prefer to configure Rails 3.1 to ignore files ending in .coffee~. Is there an easy way to do this?
I thought this was a defect in the require_tree method; and it sort of is,
seems to be a few issues filed on this:
https://github.com/rails/rails/issues/1863#issuecomment-1543809 (Rails)
https://github.com/sstephenson/sprockets/pull/119 (Sprockets)
https://github.com/sstephenson/hike/issues/9 (Hike, fix was made here)
looks like it was fixed recently, after Rails rc4 (hike-1.1.0), looks like hike-1.2.0 has been released with the fix, you could try updating your Gemfile to use the newer version

Resources