Ok, I thought I knew what I was doing and am instead immensely confused by the vast amount of conflicting resources on the internet.
I have a rails 3 app. I want to take prototype out of this app completely and ONLY use jQuery. Some of this code is in rjs files, but most of it is in format.js{} methods in the project controllers.
I found this railscast, which makes it seem like I can do the following for any given action:
def action_name
#do stuff
respond_to do |format|
format.js
#format other types
end
end
and then put my jquery code that I want to execute in a file called action_name.js.erb.
BUT I tried doing this AFTER removing prototype from my application (changing my rails.js file to jquery, and not including the prototype.js in my page header), and I got this error:
RJS error:
TypeError: $ is not a function
Why is it trying to call rjs and not recognizing my jquery? am I supposed to use rjs templates instead of .js.erb files? I thought I removed prototype from my application – did I miss something?
Most of all, is there a DEFINITIVE way to do this conversion from Prototype to jQuery that is up to date for Rails 3 as of February 2011? I’m so confused on the best way to do this, and what I should be using (rjs files or js.erb files).
Thanks so much and I can edit in more info if needed.
as for rails 3
as you did:
install the unobtrusive jquery adaptor enough in development environment since this is used only to install and remove js files
then after bundlde install run
this takes care of the jquery code that ahook on data- html5 tags unobtrusively such as remote ajax
requests or remote submits.
in order to use rjs, the defult prototype helpers should be redefined to emit jquery code
to do this, use the jrails gem
this takes care of old prototype functions like observe form, dom insertion and replacement methods etc.
with this you can continue using your rjs temlates or write inline js with render :update
probably because of the limitations of rjs (sophisticated js should still be written as strings to the page resopnse), people prefer js.erb although it is the two ugliest code formats on earth put together, jeez