Rails w/ jquery


#1

Greetings all,

I think many fellow rails developers are using jquery extensively now
and some one may already solved my problem:

rails’ RJS facility has helper methods like “replace_html”, they
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!

Difei


#2

Difei Z. wrote:

Greetings all,

I think many fellow rails developers are using jquery extensively now
and some one may already solved my problem:

rails’ RJS facility has helper methods like “replace_html”, they
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!

Difei

now I know “render :partial” works in js.erb, but why not “render
:action”? A “render :action => :new” gives “Rendered resources/_new” in
the log, why? Thanks!


#3

On Mon, Mar 2, 2009 at 11:31 PM, Difei Z.
removed_email_address@domain.invalid wrote:

Greetings all,

I think many fellow rails developers are using jquery extensively now
and some one may already solved my problem:

rails’ RJS facility has helper methods like “replace_html”, they
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 this in my application.html.erb

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.


Greg D.
http://destiney.com/


#4

On Wed, Mar 4, 2009 at 7:55 AM, Starr H. removed_email_address@domain.invalid
wrote:

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

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.


Greg D.
http://destiney.com/


#5

On Tue, 3 Mar 2009 20:25:58 -0600
Greg D. removed_email_address@domain.invalid 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 H.
My blog: http://starrhorne.com
Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/


#6

On Wed, 4 Mar 2009 08:08:45 -0600
Greg D. removed_email_address@domain.invalid wrote:

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 H.
My blog: http://starrhorne.com
Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/


#7

Starr H. wrote:

On Tue, 3 Mar 2009 20:25:58 -0600
Greg D. removed_email_address@domain.invalid 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 H.
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.


#8

This may or may not answer your question, but I recently discovered a
rails plugin called jrails which integrates jquery into rails very
similar to the way prototype comes in rails.

installing jrails allows you to use this:
<%= javascript_include_tag :defaults %>
to include jquery library files
and there are other benefits and integrations, some of which i am
pretty sure include helper methods for rjs.
so i would try looking into the details for jrails… hope that
helps… J

On Mar 3, 12:31 am, Difei Z. removed_email_address@domain.invalid


#9

Difei Z. wrote:

Starr H. wrote:

On Tue, 3 Mar 2009 20:25:58 -0600
Greg D. removed_email_address@domain.invalid 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 H.
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!


#10

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