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.
36b07c5c8b1e802259386e29dc705cd3?d=identicon&s=25 Difei Zhao (difei)
on 2009-03-03 06: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
36b07c5c8b1e802259386e29dc705cd3?d=identicon&s=25 Difei Zhao (difei)
on 2009-03-03 07:19
Difei Zhao 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!
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2009-03-04 03:26
(Received via mailing list)
On Mon, Mar 2, 2009 at 11:31 PM, Difei Zhao
<rails-mailing-list@andreas-s.net> 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 Donald
http://destiney.com/
170e2a48994775e4c298c302e6814f81?d=identicon&s=25 Starr Horne (Guest)
on 2009-03-04 14:56
(Received via mailing list)
On Tue, 3 Mar 2009 20:25:58 -0600
Greg Donald <gdonald@gmail.com> 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/
Aad37b5f7116c8d1f547d23b37566032?d=identicon&s=25 Greg Donald (destiney)
on 2009-03-04 15:09
(Received via mailing list)
On Wed, Mar 4, 2009 at 7:55 AM, Starr Horne <starr@chatspring.com>
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 Donald
http://destiney.com/
170e2a48994775e4c298c302e6814f81?d=identicon&s=25 Starr Horne (Guest)
on 2009-03-04 15:35
(Received via mailing list)
On Wed, 4 Mar 2009 08:08:45 -0600
Greg Donald <gdonald@gmail.com> 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 Horne
My blog: http://starrhorne.com
Check out my Helpdesk RailsKit: http://railskits.com/helpdesk/
Fc5bdda977c118e3bb76f52fccd506e1?d=identicon&s=25 johncgilliland@gmail.com (Guest)
on 2009-03-04 15: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 Zhao <rails-mailing-l...@andreas-s.net>
36b07c5c8b1e802259386e29dc705cd3?d=identicon&s=25 Difei Zhao (difei)
on 2009-03-04 17:49
Starr Horne wrote:
> On Tue, 3 Mar 2009 20:25:58 -0600
> Greg Donald <gdonald@gmail.com> 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.
3726af4dd23b3e60e910113e673793c2?d=identicon&s=25 Daniel Trelogan (dtrelogan)
on 2010-10-09 20:06
Difei Zhao wrote:
> Starr Horne wrote:
>> On Tue, 3 Mar 2009 20:25:58 -0600
>> Greg Donald <gdonald@gmail.com> 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!
3726af4dd23b3e60e910113e673793c2?d=identicon&s=25 Daniel Trelogan (dtrelogan)
on 2010-10-09 22: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.