Forum: Ruby on Rails rails w/ jquery

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Difei Z. (Guest)
on 2009-03-03 07:31
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
Difei Z. (Guest)
on 2009-03-03 08:19
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!
Greg D. (Guest)
on 2009-03-04 04:26
(Received via mailing list)
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

<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.


--
Greg D.
http://destiney.com/
Starr H. (Guest)
on 2009-03-04 15:56
(Received via mailing list)
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/
Greg D. (Guest)
on 2009-03-04 16:09
(Received via mailing list)
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/
Starr H. (Guest)
on 2009-03-04 16:35
(Received via mailing list)
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/
(Guest)
on 2009-03-04 16:57
(Received via mailing list)
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>
Difei Z. (Guest)
on 2009-03-04 18:49
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.
Daniel T. (Guest)
on 2010-10-09 22:06
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!
Daniel T. (Guest)
on 2010-10-10 00:36
> 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
This topic is locked and can not be replied to.