What jquery rails 3 tutorial has worked well for you?
I have looked at several tutorials involving rails 3 and jquery. The tutorial at http://c.kat.pe/post/how-to-use-jquery-for-rails-3/ looked promising. However, I get the errors of document.on is not a function
and $("a[data-remote=true]").livequery is not a function
I get the feeling that I should look at another tutorial or just use jquery raw and not install a ruby gem for jque开发者_运维知识库ry. Any advice? Thanks!
Regarding the jquery-gem: I have stopped using it. I recall on a couple of occasions that it failed to copy over the rails.js file correctly after I ran the rake config command. That might have happened to you here. Perhaps it's copied the file over with a different name..
Anyway, there are better ways to do jquery imo:
- use the google loader (you will need to sign up for a google api key)
- use a google ajax api link
- start using the compass gem, and install the html5-boilerplate compass add-on
Option 3 generates code that uses options 1 and 2, and makes sure that your app resorts to a local version of jquery in the event that the google api link is down.
Anyway, here's a link to something that looks quite promising - A guy is building a website and documenting how he did it - there are a few instances of jquery use, most notably here and here in a post titled Ajax Forms
I use jQuery raw and I don't rely on any built-in Rails JavaScript. Ryan Bates has some good Railscasts on the topic but he seems to recommend installing the gem. For me, Rails is a convenient MVC framework that makes it super easy to get things up and running, but I don't like it to control how my views talk to my controllers. I'm more of a JavaScript developer.
They're two completely different/independent entities. I would really learn each separately and then maybe jump into something like jRails if you can understand the source code. Try loading up a firebug console on any webpage and start playing with all ofthe jQuery selectors and functions listed in the API.
After a little pain and investigation around the issue, it looks like running the "rails g jquery:install" command chucks an certificate verification error when it tries to pull the jQuery ULS adaptor (whatever this is) from Github.
Root of this error seems to be windows doesn't know how to lookup the CA certs properly (I use windows 7, not sure if other windows versions have this issue). Also not sure where the fix lies (ruby / Github / jquery-install gem) ? In any case, this post gave me the workaround : http://udevi-community.blogspot.com/2011/01/create-sample-rails-3-application.html
You need to :
- Download this file locally (say to "C:\Ruby\certs\cacert.pem")
Modify _RUBY_HOME_\lib\ruby\_VERSION_\open_uri.rb, search for a line starting "http.verify_mode =" and add in the following line below it (making sure to adjust the right-hand side to match where you saved the cacert.pem file) :
http.ca_file = 'C:\Ruby\certs\cacert.pem'
With that new line in place, try running "rails g jquery:install" again - this time it should hopefully overwrite the rails.js file, and the prototype.js related errors should vanish.
精彩评论