rails / jquery-rails Goto Github PK
View Code? Open in Web Editor NEWA gem to automate using jQuery with Rails
License: MIT License
A gem to automate using jQuery with Rails
License: MIT License
Hi, I updated to the new version, and restarted my server, but it still serves the old jquery. I am just running in development mode.
I did rake assets:clean
just to be sure, but it did make any difference.
I am running rails 3.1.0. Is there something else I need to do to remove the old jquery. Now it is still loading jquery 1.6.2.
If you need more info, just ask.
Rails 3.0.6, jquery-rails 1.0.9, ruby 1.9.2-p180 and p136
below usage does not work even though a match is found
assert_select_jquery "#userInfo"
assert_select_jquery :replaceWith
assert_select_jquery :replaceWith, "#userInfo"
But this one does
assert_select_jquery :replaceWith,"#userInfo" do
assert_select "input#user_first_name"
end
This is the js file that answers for the edit action
#edit.js.erb
$('#userInfo').replaceWith("<%=escape_javascript(render :partial=>"edit_user", :locals=>{:user => @user} )%>");
and this is the partial that is rendered
#_edit_user.html.erb
<div class="profile twoPixRadius cocoBorder user lightGrayFade" id="userInfo">
<%= form_for(@user, :remote => true, :id=>"edit_user_info" ) do |f| %>
<h2> My Information</h2>
<div>
<label for="user_first_name">Name</label>
<%= f.text_field :first_name, :size=>"60", :class=>"text-input" %>
<%= f.text_field :last_name, :size=>"60", :class=>"text-input" %>
<br/>
</div>
<div>
<%= f.submit "Update", :class =>"vportant" %>
<input type="button" value="Cancel" name="cancel" id="user_cancel"/>
</div>
<% end %>
</div>
Solution Some preliminary testing shows that it works even for the previous cases when adding the PATTERN_HTML to the regex pattern even when no block was given (on line 55 of assert_select.rb). I have not tested for jquery_opt.
#assert_select.rb
53 pattern = "\\.#{jquery_method || '\\w+'}\\("
54 pattern = "#{pattern}['\"]#{jquery_opt}['\"],?\\s*" if jquery_opt
->55 pattern = "#{pattern}#{PATTERN_HTML}" #if block removed to make this work
56 pattern = "(?:jQuery|\\$)\\(['\"]#{id}['\"]\\)#{pattern}" if id
Since 2.0.3 (16 August 2012) and upwards, anything with :remote => true (eg. link with :remote => true) has stopped working on IE6. Unfortunately we still have a lot of users on IE6 which I cannot get rid of!
Downgrading back to jquery-rails 2.0.2 works fine.
I'm using rails 3.2.6 at present.
Is anyone else having this problem?
I'm on Rails 3.0.8 and jquery-rails 1.0.12. I ran the jquery generator to install the javascripts. Both jquery and jquery_ujs are included in my defaults and I can verify they are being included on the page.
Here's my javascript:
jQuery(function($) {
$("#deactivate")
.bind("ajax:success", function() {
alert("HELLO");
})
.bind("ajax:error", function() {
alert("GOODBYE");
}
);
});
The link:
= link_to 'Deactivate', activate_patient_path(patient), :id => 'deactivate', :class => "button button-red", :remote => true
The activate action:
def activate
patient = Patient.find(params[:id])
patient.do_not_call = !patient.do_not_call
if patient.save
render :json => :success
else
render :status => 500, :json => :success
end
end
The ajax call seems to be working fine. The action is triggered and I can see the changes in the database. However, the ajax callbacks are not being triggered. I can't get any of them to work. I can get other events, such as click, to work perfectly.
If I debug rails_ujs in Firebug I see that the following code gets ran from the Rails ajax block:
success: function(data, status, xhr) {
element.trigger('ajax:success', [data, status, xhr]);
}
If I execute
element = $("#deactivate");
element.trigger('ajax:success');
in the console I can get the callback to trigger.
Using Firebug, if I put a breakpoint at the element.trigger('ajax:success', [data, status, xhr]) line in rails_ujs and then bind
Given there are no real tests for this gem I suggest to remove them. It's not adapted to RSpec2 and outdated since Rails::Generators.configure! now takes one argument.
Also, I think it makes sense since this gem only provides jquery through the asset pipeline and has not logic to test.
The reason is because if a project dynamically runs all tests over all engines that are loaded, it has to skip jquery-rails explicitly to make tests pass.
jQuery and jQuery UI was updated in the sources but there are no corresponding Gem release.
What is the rationale behind this ?
Here's a gem that already provides this behaviour: https://github.com/kenn/jquery-rails-cdn
I think this should be the default behaviour of the jquery-rails
gem.
It seems like a waste of resources if we are all compiling our own copies of jQuery and jquery-ui into our application.js
.
Sites like Twitter, Stack Overflow, Posterous, and Foursquare are ensuring that your users will already have a cached copy of jQuery ready for you to use, because they all reference Google's CDN. This provides cross-site caching.
You may find it helpful to read the following articles:
In order to implement this, we would need to provide an install generator (rails g jquery:install
), since we'll need to make some changes to the Rails application:
//= require jquery
from application.js
= jquery_include_tag :google_schemeless
to your layoutconfig.assets.precompile += ['jquery.js']
to application.rb
(provides a fallback in case Google's CDN goes down, is blocked, you're offline, etc.)Another bug fix version was released http://blog.jquery.com/2012/09/20/jquery-1-8-2-released/
Since upgrading, any form that has more than one radio with required=true on it will not submit. It appears they are failing some kind of validation.
Excuse the crude example, but if you fill out the form at http://jsfiddle.net/Rumpp/2/ & try to submit it, check the network tab and observe that no POST is ever made. Removing the required="required" on the radios fixes the issue.
edit: I think this line in UJS may be the culprit 463ace5#L1L240
There seem to be an issue with performance using 2.1.2 of this gem in IE8. The selectors used in jquery_ujs are interpreted very slowly by jquery.
This is most likely not a problem of jquery-rails, but I wanted to report it here if more people experience this issue.
There are many good reasons that someone might not be using the asset pipeline, or might not be using it yet, even if they are using the rest of rails-3.1.
For people not using the asset pipeline, the generators remain useful and correct, and should be retained.
As of jQuery 1.7, the .delegate()
method was deprecated. Any chance of updating this so that when it goes away our code does not inadvertently break when jQuery finally removes it?
$('#selector').attr('attribtueName') seems to return the entire element in an array instead of getting attributeValue.
I just included jquery_ujs twice (once in the head, once in the footer - merge accident) and did not get a warning like "jquery-ujs has already been loaded!", but instead all Rails-related events where fired twice: clicking an a[data-remote] triggered 2 ajax requests, forms are submitted twice.
We need to update jQuery to version 1.8.1. Changelog: http://blog.jquery.com/2012/08/30/jquery-1-8-1-released/
It’s just bugfix release, so I think it is clean to compatibility issues with jquery-rails,
for 2 days, the gem update command give me :
ruby 1.8.7 (2011-06-30 patchlevel 352) [i386-mingw32]
Updating installed gems
Updating jquery-rails
ERROR: While executing gem ... (Gem::DependencyError)
Unable to resolve dependencies: jquery-rails requires railties (< 5.0, >= 3.2.0.beta)
So it break on my system without rails 3.2 beta....
I think a new release shoud no break the current production version
Any idea to correct it ?
With reference to these two issues (on jquery-ujs) that have been resolved. Is there an ETA on when jquery-rails will be updated with these fixes?
Issues:
jquery/jquery#751 (comment)
rails/jquery-ujs#295
Fixed: rails/jquery-ujs#300
My team is having the same issue with XMLHTTP disabled in Internet Explorer 8. We're using the jquery-rails gem.
I like the approach of having both a minified and regular version of jquery. The problem is that this results in javascript_include_tag :all always including whichever one was not specified in the bulk of the js files. I'm really not sure how to solve this...
In my case I could just put it in a subdirectory, but that breaks down if the :recursive option is set.
Ideas?
Hey guys,
I just packaged up jQuery UI for the asset pipeline: http://www.solitr.com/blog/2012/02/jquery-ui-rails-gem-for-the-asset-pipeline/
I was wondering what you thought about moving the jquery-ui.js that's currently shipping with jquery-rails into the jquery-ui-rails gem?
Right now we can't add a "jquery-ui.js" asset to jquery-ui-rails, because it would conflict with jquery-rails's version. (Which of the two gets picked up by Sprockets would be undefined, so that's asking for trouble.) So here's my suggestion:
What do you think?
[1] I was thinking whether jquery-rails should depend on jquery-ui-rails so people get jquery-ui automatically. But since jquery-ui-rails adds a bunch of files (like "jquery.ui.datepicker.js") into the asset space that might conceivably conflict with user-supplied jQuery UI assets, I think it's best not to force it onto people, and instead require them to add jquery-ui-rails to their Gemfile if they want it.
jquery ui functions dont work if
config.assets.digest = false
rails (3.2.3)
jquery-rails (2.0.2)
by default the digest is false except in the production environment. The js files are successfully included but the browser console shows errors like
autocomplete is not a function
dialog is not a function
I was curious as I'm learning Rails from scratch.
Whenever I run a bundle install command on any Rails application it always takes several minutes on "Installing jquey-rails" - why is that?
Every other gem in my Gemfile bundles quickly in 1 to 10 seconds, except this gem.
Any ideas?
Since people are depending on this gem to provide the jQuery library, it should be more obvious which version of jQuery is used to people viewing the repository.
When I run rake assets:precompile
from my Rails 4 app, it gives an error:
couldn't find file 'jquery'
I'm using the master branch of jquery-rails.
After being stable for months, jquery-rails 2.0.0 inexplicably added a dependency to the new Rails release candidate, 3.2.8.rc. This breaks the sample application for a bunch of Rails Tutorial readers, among others—anyone using 2.0.0 with Rails 3.2.x is probably affected. Version 2.0.2 works fine, and I've updated the tutorial's Gemfile accordingly, but this still seems worth fixing.
By the way, I'm genuinely curious to know how this happened. How could a previous version of a gem suddenly depend on an as-yet unreleased version of Rails?
Is it possible to get this gem updated to the latest jqueryui (1.8.16) ?
There is a bug in 1.8.14 that has since been fixed, so I'm pretty keen to get the latest version
thanks,
-adam
Hi,
Do you plan to add support for any jQuery CDN? It could be great to have option to include local copy of jQuery in development envirement and point the user's browser to any CDN in production (for example, google).
It also solves the problem of distributing minified versions.
Thanks.
Feature Suggestion: Support non-remote non-get links with request entities.
Given the following:
link_to title, resource, :method => :put, :data => { :params => { "a" => "x", "b" => "y" } }
This, when clicked, should send a PUT
request with the params above as the request entity in either text/www-url-form-encoded
or application/json
. It looks like there's code to handle this scenario in a :remote => true
link; handle this case even when it is not a :remote => true
link.
I ran into an interesting problem where I had a remote form:
#index.html.erb#quick_reply
<%= simple_form_for [@discussion, @post], :remote => true do |f| %>
<%= f.input :body, :input_html => {:class => 'span12 short_text_area' } %>
<%= f.submit 'Post Reply', :class => 'btn-primary' %>
<% end %>
And when the form submitted, it was processed twice. I ended up fixing by removing
//= require jquery
//= require jquery_ujs
from my application.js file. This is in exact opposition with what this gem's documentation says, but it seems that I'm getting the JQuery scripts without having them in the manifest file. Does the doc need updated or is there something else going on here?
Jquery seems not to be loaded when I put my js code in the asset pipeline.
It still works when i keep it in the view template file.
Any suggestion?
thanks
jQuery 1.8.3 was released last week: http://blog.jquery.com/2012/11/13/jquery-1-8-3-released/.
ERROR: While executing gem ... (Gem::DependencyError)
Hope you continue your good job!
Serge
Errno::ENAMETOOLONG is throwing in the javascript_include_tag
12: <% end %>
13:
14: <%= stylesheet_link_tag 'application' %>
15: <%= javascript_include_tag 'application' %>
16: <%= csrf_meta_tag %>
17:
18:
link_to "do it", :data => {:disable_with => 'Please wait...'}
Please note that this is not a remote link.
It works as expected in latest Chrome and latest Firefox.
It never shows "Please wait..." in the latest Safari (feels like a cosmetic rendering bug in Safari, v6 just seems generally buggy, earlier versions worked fine)
In IE8 and IE9 it shows "Please wait..." but doesn't make the request. It just hangs. So the link is essentially broken.
I tested this with 2.0.2 and with 2.1.3.
With jQuery 1.4.2 and Rails 3.x (manual method), I could override and bind the ajax to invoke callbacks on ajax success. However, this doesn't work with jquery-ujs 1.0.12 and Rails 3.1 (git) that leads to two requests to be invoked instead of one. I suspect this is related to issue #10 Here is an example:
Generate test app
rails new test123 cd test123 rails g scaffold states name:string abbr:string rake db:migrate
Make sure we're usin the latest 3-1-stable by modify Gemfile
:
gem 'rails', :git => 'git://github.com/rails/rails.git', :branch => '3-1-stable'
bundle install
Modify following files:
app/controllers/states_controller.rb
:
def new @state = State.new respond_to do |format| format.html # new.html.erb format.js { render :text => 'hello world' } # we add this end end
app/views/states/index.html.erb
:
<%= link_to 'New State', new_state_path, :remote => true %>
app/assets/javascripts/states.js
:
$(function(){ $('a[data-remote=true]').live('click', function(){ $.get(this.href, function(data) { alert(data); }); return false; }); });
With the help of Firebug, it is indicated that there are 2 requests invoked. This might explain that the binding is not successful.
Any chance once rails 3.1 is officially released this can be submitted to http://www.cdnjs.com/ or other public cdn?
maybe in rails 3.2 asset pipeline can use public cdn by default in production mode for external libs :)
jQuery 1.8.0 is compatible with with the latest versions of jQuery UI (1.8.22), and jQuery Mobile (1.1.1).
There are more details at the full blog post
http://stackoverflow.com/questions/11873985/jquery-in-rails-3-1-1-always-gives-domexception
Basically, if you turn on 'Pause on exceptions' in a browser JS debugger, and click anywhere on the page, exceptions are raised in jquery.
Not an issue per se, but I wonder if it would be better to bump the minor version of jquery-rails when a new minor version of jquery is bundled?
For example, 1.0.17 of jquery-rails included jQuery 1.7. If it were tagged as 1.1.0 instead, we could more easily manage the version of jQuery we want in our Gemfile. It's not currently possible to bundle update
and get the latest patch release of a particular jQuery version.
# We want jQuery to 1.6.x
gem 'jquery-rails', '~>1.0'
Of course, this is tricky to manage sensibly for jquery-rails because it essentially bundles up a bunch of different libraries.
What I'm wondering aloud is whether there is a more meaningful way to tag jquery-rails releases. What does everyone think?
weirdly, rails g jquery isnt recognized in my app... is this happening just here?
I've turned asset pipeline off here because it was serving some files, but not others and tried to generate the driver but there's no jquery generators for the app..
rails g doesnt show nothing for jquery here also...
rails31/gems/jquery-rails-1.0.12
Hello. I have an app that is heavily relied on jquery. I just updated to 2.2.0 version and got the following error in the Firebug console:
TypeError: $(...).live is not a function
....get(0).nodeName.toUpperCase()=="LI"?(i.replaceWith(o),i=o):i.empty().append(n)
And part of my functionality was broken. When i reverted to 2.1.4 version everything was OK again.
require jquery
should send me the latest jquery
require jquery-1.6
should send me the latest 1.6 release
etc.
same for jquery-ui and jquery_ujs
Use case: when jquery is a dependency of an engine, you (maintainer of the engine) don't want to freeze jquery-rails to the supported version of jquery-rails containing the supported version of the required library.
Gem dependencies are meant for lib compatibilities and should not get in the way transversally.
edit: just saw #2
.. Maybe reconsider?
Would be nice if there was a list of what gem version corresponds to what version of jquery in an easy to find place. Might be even better if the version numbers moved in sync, since sometimes require a specific version for other software you're using.
Unfortunately I'm trying to use sprockets >= 2.3, but because I am using jquery-rails v2.0 that depends on sprockets 2.1.2, I am unable to load up the correct version of sprockets.
Bundler could not find compatible versions for gem "sprockets":
In Gemfile:
sprockets (>= 2.3) ruby
jquery-rails (>= 2.0) ruby depends on
sprockets (2.1.2)```
aka47 oche chetki pacan!
it would help if you would also add each package of jquery-ui into the gem datepicker, timepicker, effects etc.. so one could decide to use all of them or just pick some of them
Hello,
As many of you I guess, I like to Ctrl+Click to open pages in another tab. Because of the click handler on remote link this does not work.
For now, I'm trying to edit the live("click.rails") function with this one :
$(rails.linkClickSelector).live('click.rails', function(e) {
var link = $(this);
if (!rails.allowAction(link)) return rails.stopEverything(e);
if (link.data('remote') !== undefined) {
if (e.which == 2 || e.metaKey || e.ctrlKey){
return true
} else {
rails.handleRemote(link);
return false;
}
} else if (link.data('method')) {
rails.handleMethod(link);
return false;
}
});
But I haven't tested it properly yet.
Any thoughts ?
jQuery 1.6.3 broke some stuff on jquery-ujs. Until it's fixed, I'm hesitant to make it the default for jquery-rails. I opened a ticket in the jquery bug tracker here: http://bugs.jquery.com/ticket/10202
In the meantime, I'll open this ticket to keep track and let people know why jquery-rails is staying at 1.6.2 for the time being.
Opera 11.11. bind("ajax:success") is triggered as expected, but live("ajax:success") is not triggered at all.
jquery-rail 1.0.9, jquery 1.6.1
Invalid gemspec in [/var/lib/gems/1.8/specifications/jquery-rails-2.0.1.gemspec]: invalid date format in specification: "2012-02-28 00:00:00.000000000Z"
This message is printed anytime rails commands are executed.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.