Forum: Ruby on Rails UJS in Rails 3 Beta

Posted by overture (Guest)
on 2010-02-08 12:10
(Received via mailing list)
Hi All,

Does anyone know if there are any good examples of how to use the
unobtrusive javascript functionality in Rails 3.  I've read the
release notes but I can't seem to get things working.

I've just set up a simple Rails app with a Post model.  In the "_form"
partial I have add the ":remote => true" parameter, as required.  When
I submit the form it saves the record asynchronously, as expected but
it doesn't redirect to the appropriated page afterwards.

Any ideas what I'm doing wrong?

Thanks!
Phil
Posted by overture (Guest)
on 2010-02-09 17:37
(Received via mailing list)
Useful link I found:-

http://joshhuckabee.com/jquery-rails-3
Posted by Greg Donald (destiney)
on 2010-02-09 17:43
(Received via mailing list)
On Tue, Feb 9, 2010 at 10:35 AM, overture <phil.mcclure@gmail.com> 
wrote:
> Useful link I found:-
>
> http://joshhuckabee.com/jquery-rails-3

Does the HTML5 stuff in Rails3 degrade to something else for browsers
that don't support it yet?  I've read all the Rails3 news I can find
but don't see this answered anywhere.


--
Greg Donald
destiney.com | gregdonald.com
Posted by Steve Klabnik (Guest)
on 2010-02-09 17:56
(Received via mailing list)
I don't think that Rails 3 is using anything that wouldn't already be
supported by older browsers. It's not like it's sticking in <canvas> by
default, just using some special named parameters. A large goal with 
HTML5
was backward compatibility.
Posted by overture (Guest)
on 2010-02-09 21:41
(Received via mailing list)
Maybe there will be some good examples available soon.  Hope so.
Posted by overture (Guest)
on 2010-02-11 22:34
(Received via mailing list)
I just did a post on using UJS in Rails 3 -
http://therailworld.com/posts/26-Using-Prototype-and-JQuery-with-Rails3-UJS-
Posted by Greg Donald (destiney)
on 2010-02-12 01:53
(Received via mailing list)
On Thu, Feb 11, 2010 at 3:33 PM, overture <phil.mcclure@gmail.com> 
wrote:
> I just did a post on using UJS in Rails 3 -
> http://therailworld.com/posts/26-Using-Prototype-and-JQuery-with-Rails3-UJS-

<snip>
so if you wanted to use JQuery or MooTools you would need to do make
your own solution.
</snip>

Wrong.  There is JRails which uses jQuery and provides all same
javascript helpers.

http://github.com/aaronchi/jrails

In addition, any jQuery you want to run through the page object is as 
simple as:

page << "$('#foo').bar();"



--
Greg Donald
destiney.com | gregdonald.com
Posted by Emery Finkelstein (Guest)
on 2010-02-12 10:07
(Received via mailing list)
JRails is just a drop in replacement for PrototypeHelper in Rails
releases prior to 3.

Rails 3 looks is phasing out PrototypeHelper in favour of UJS. The
goal of UJS is to eliminate all inline Javascript. The end result of
this is that all your favourite javascript generating helpers will be
deprecated. link_to_remote, form_remote_for, link_to_function, and the
rest will be gone.

Yes. a driver file will need to be created for each of mootools,
jquery or any other javascript frame work to use the new :remote =>
true syntax of  Rails 3. But they're pretty simple files that don't
change too much from the prototype example that ships with rails
("rails.js").

You can use the new prototype_legacy_helper or a slightly modified
JRails with Rails 3 to restore the old way of doing Javascript in
Rails. But it wouldn't be the Rails 3 way of doing things.

By the time Rails 3 gets a proper release there will be drivers for
all the popular Javascript frameworks.
Posted by Emery Finkelstein (Guest)
on 2010-02-12 21:34
(Received via mailing list)
I'm going to retract a part of my response, particularly the bit
stating that plugins/gems like JRails are unnecessary in Rails 3.
After doing a little more digging on the issue, it looks like JRails
will still be required if you're looking to use RJS templates to
generate JQuery.

This goes for other JS frameworks like Mootools or Dojo as well
Posted by overture (Guest)
on 2010-02-14 19:45
(Received via mailing list)
The underlying meaning of this statement is; Rails as a framework use
to favour a certain Javascript framework (Prototype).  This doesn't
mean that you alone would need to write your own solution for JQuery,
but someone, somewhere *did* have to write JRails.  Likewise, if you
wanted to use Mootools, someone would need to write a solution for
it.  Rails 3 and UJS solve this problem, among others.
Posted by Ralph Edge (rledge21)
on 2010-02-25 10:54
Greg Donald wrote:

> Wrong.  There is JRails which uses jQuery and provides all same
> javascript helpers.
> 
> http://github.com/aaronchi/jrails


JRails is obtrusive javascript, where rails 3 implements unobtrusive 
javascript.  Using JRails along with Rails 3 just seems...wrong.  I 
always thought using JRails in itself was kind of wrong, just because 
JQuery focuses more on unobtrusive javascript.  This was the reason I 
started using JQuery in the first place.

I think the correct solution is to look at the new Implementation of the 
unobtrusive prototype helpers in Rails 3, and write similar unobtrusive 
JQuery, using JRails to help.
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.