Rails 3.0 required javascript libraries for method delete - javascript

I was wondering what are the specific javascript libraries required to get the method => delete to work. Also, I'm having problems because I want to use the jquery library, and if I include :defaults it doesn't work. Is there a way to integrate the two?
Thank you.

jQuery can run in Rails if you include the UJS script. Your best option is to use the following:
https://github.com/indirect/jquery-rails

Related

Custom JavaScript to existing Joomla core module

I have developed a custom Joomla template, and I need to add a piece of custom javascript to a Joomla core module (mod_articles_news), without a plugin, if possible (this should be so simple that I don't think I want to use a third party plugin for that). And async, if possible.
I have been searching thoroughly, but haven't found the perfect solution. Either they want me to install a plugin or the solution refers to a custom written module (suggesting to add JS before installation of module) while I am dealing with a core module (Articles Newsflash) that is already installed per definition. (The reason I need to use JS is to make a conditional design change, presently not possible with CSS).
I have been following the steps outlined here, but to no avail. Namely, I added the following code into the module's template folder (mod_articles_news/tmpl/my-template-name.php)
<?php
JHtml::script(Juri::base() . 'templates/my-template-name/js/myScript.js');
?>
(Of course, I have added the myScript.js file into the above location).
When checking it live, nothing happens, the browser is not loading my JavaScript at all (the script itself is tested and it works).
Please help me what I am missing here. Thank you in advance!
If you want to do customization you should use a Joomla! template for this. A template determines the basic HTML including the necessary CSS/JS for your site. In addition it can contain overrides for modules and components so you can do even more customization without touching any of the original code.
What you want to do sounds like a simple customization. Just add any CSS/JS which is necessary to achieve your task to the template.
You could try
<?php
JHTML::script('templates/my-template-name/js/myScript.js');
?>
alternatively, is there any reason you can't add it via your custom template, as suggested by Sven Bluege

The situation about Rails/JQuery/Prototype/RJS

I am trying to use Jquery / ajax in rails 3.0.7. I do not understand what is the current situation about Jquery and rails.
Everywhere there is tons of hacks and plugins and scripts to use JQuery. So :
Is there an "official way" to use jquery in rails 3.0.x or are all method just customs hacks?
Is there a rjs or equivalent with Jquery for rails 3.0.x ?
What are all those jquery something files for rails, when jquery official site only propose one file?
From what i saw protoype is easy to use for ajax, why is it dropped in favor of jquery for rails 3.1.x?
As of Rails 3, the JavaScript library you use is up to you. There are "drivers" created for the Rails primitives for Prototype and for jQuery. To set up jQuery, simply include the jquery-rails gem in your bundle file:
gem "jquery-rails"
...then run bundle install.
If you don't already have jQuery installed in the project, you can run this command to install it:
rails generate jquery:install
In Rails 3.1, jQuery is the default, rather than Prototype. I personally believe it's because jQuery plays well with other JavaScript libraries, and that flexibility makes it more appealing to something like Rails. However, there are tons of arguments on all sides. I'm not sure if there's a definitive reason besides "jQuery is the new hotness."

rails jQuery Accordion

How do you set up jQuery to work with rails. I specifically want to use the accordion feature. I have used this before with PHP but i cannot work out where everything needs to go in a rails application. I have imported jQuery into the javascript folder and included it in the application. My HTML is laid out correctly, but i don't understand where the following should go:
<script>
$(document).ready(function() {
$("#accordion").accordion();
});
</script>
I have also tried installing jRails and using the scriptaculous Accordion, but neither of them worked either, so I think I am missing some vital link between javascript and rails.
I have looked all over for some explicit instructions on how to set it up, if anyone has a link or can walk me through it it would be appreciated.
After checking firebug I can see I am getting the following error:
$("#accordion").accordion is not a function
I call jQuery before I call application.js
You just need put this line in your view if you don't want UJS system.
Instead you can put it on your application.js and require it in your head node.
You also need to make sure that you commented out default javascript libraries, because out of the box, Rails applications come packaged with prototype which will conflict with your jQuery library.
It looks like this :
<%= javascript_include_tag :defaults %>
Are you hitting any javascript errors in firebug?
I downloaded the wrong jQuery library, the link on the website pointed to an incomplete .js file. Download what you need from: http://jqueryui.com/download don't just download the file from http://docs.jquery.com/Downloading_jQuery
Only call the javascript files you need directly in your standard layout, do not use the :defaults option.
If you are going to use a lot of fancy jQuery things on different pages add the document ready function to your view, else add it to your application.js
Ensure that you call the jQuery UI files before the application.js file or it will not find the functions in the right order.

how do i avoid including jquery twice?

i have a service i'm building, which will be included as JS on client web pages. optimally, i want to build the service using jquery.
the case may arise, where the page already has JQ included.
how do i avoid including JQ twice in the page? how do i make sure i still have the desired JQ functionality, even if the page has already included an older version of JQ?
is the only solution simply abandoning JQ and going with hand-coded script?
Check for the existence of jQuery and match the version you need against jQuery.fn.jquery.
from the linkedin jquery group:
Ever want to use the latest jQuery, but old code or components leaves you with an older version? Well this standalone version can be included anywhere on the page and will take a custom name space of jQuery14, and will not affect jQuery or $ in any way. Also, easy way to integrate among other frameworks.
http://www.matthewdunham.com/jquery-1.4.2.min.standalone.js

Jquery + Rails problematic, is that true?

I saw comments in a previous question saying that it is best to use Prototype with Rails. However, my own experience is that Jquery is a superior Javascript library. Being new to Rails, I have not yet investigated how to use Jquery with Rails but I assumed this would work. Is it correct that this may be a problematic combination - especially in relation to Ajax - and that I may need to use Prototype instead?
I've worked on all my projects since 3 years with rails and (exclusively) jquery. Never really encountered any (serious) problems so far.
There is a plugin called jrails, which acts as a drop-in replacement for prototype.
http://github.com/aaronchi/jrails/tree/master
Update: with it you can get all of the same default Rails helpers for javascript functionality using
I use both jQuery and Prototype with rails. jQuery for DOM manipulation and thickbox (my favorite light box plugin), but i use prototype for AJAX right now. no particular reason, just haven't wanted to use the jrails plugin yet. im sure i will do this in the future. if you use both, this should be in your head tag:
<%= javascript_include_tag 'prototype' %>
<%= javascript_include_tag 'jquery' %>
<script type="text/javascript">
var $j = jQuery.noConflict();
</script>
Then use jQuery with $j
I use jQuery and Rails on the job in a production environment and have only nice things to say. We use AJAX too. The only problem I can think of is the jQuery.noConflict() call that's necessary if you're using jQuery and prototype together.
The only problem with jrails is rjs testing. But this patch adds 5 of 8 missing test helpers.
It won't be problematic to use jquery with rails at all, it's just not the natively supported JavaScript library. You don't actually have to use any of the JavaScript builtins in rails, and the (by default) RESTful structure of your application should make AJAX simple.
With prototype and scriptaculous, alot of the AJAX work has already been done for you. With jquery, you'll just be writing some more JavaScript yourself.
Rails was built to work with Prototype for AJAX et. al., but there's no reason you have to use Prototype. I'm a jQuery fan myself, and you can definitely use it with Rails.
You can still hook into a lot of the AJAX work that's been done in Rail with jQuery, not a problem.
And, as kmorris said, if you're using jQuery and any other javascript library on the same site, be sure to add the jQuery.noConflict() line in or else VERY bad things will happen.
Try this: https://github.com/xpepermint/js_erb
Javascript becomes part of app, i18n and js templating become available and more.

Categories