rails w/ jquery

I have this in my application.html.erb

<script src="/javascripts/prototype.js" type="text/javascript"></script> <script src="/javascripts/effects.js" type="text/javascript"></script> <script src="/javascripts/dragdrop.js" type="text/javascript"></script> <script src="/javascripts/controls.js" type="text/javascript"></script> <script src="/javascripts/jquery.js" type="text/javascript"></script> <script src="/javascripts/jquery-ui.js" type="text/javascript"></script> <script src="/javascripts/application.js" type="text/javascript"></script>

I have this in my application.js:

var $j = jQuery.noConflict();

This puts the jQuery instance into it's own namespace, leaving the $ object from prototype alone.

And then in an rjs template I can do things like:

page.replace_html 'pane_content', :partial => 'message/sent_pane' page << "$j($j.fn.nyroModal.settings.openSelector).nyroModal();"

The page object still processes Javascript, no matter what library you use.

I have successfully used the jRails plugin. You just drop it in and it changes the built in JS jelpers to use jquery. EnnerChi.com is for sale | HugeDomains

When I tried it, about 4 or 5 months ago, it did work, but it didn't play nice with prototype. Perhaps it's improved since.

Ahh. Well I never it with prototype, so I couldn't say.

SH

Starr Horne wrote:

Difei Zhao wrote:

Starr Horne wrote:

> allowed you to render partials in the .rjs file and execute the > javascript which updates the page, how can I do that using jquery? > Thanks in advance!

I have successfully used the jRails plugin. You just drop it in and it changes the built in JS jelpers to use jquery. http://ennerchi.com/projects/jrails

-- Starr Horne My blog: http://starrhorne.com Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/

Hi, since I'd like write js code by hand with jquery, so "render :partial" in .js.erb file just fills my needs.

for newbies like me who don't want to use jrails in rails 3 and might need it spelled out, rather than:

render :update do |page|   page.replace_html 'preview', :partial => 'preview' end

do something like this in your controller:

render :action => :preview

and in your preview.js.erb file do something like:

jQuery('#preview').html('<%= javascript_escape(render(:partial => "preview")) %>');

of course, you'd also need a partial named _preview.erb (or _preview.haml)

good luck!

and in your preview.js.erb file do something like:

jQuery('#preview').html('<%= javascript_escape(render(:partial => "preview")) %>');

of course, you'd also need a partial named _preview.erb (or _preview.haml)

good luck!

oops, should have said escape_javascript