Forum: Ruby on Rails Determing JS+AJAX vs. button

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.
Maciej P. (Guest)
on 2007-05-12 01:01
(Received via mailing list)
I'd like to use on browsers supporting AJAX link_to_remote or
button_to_function/remote_function and on rest button_to and link_to.

How can I determine it?
--
I've probably left my head... somewhere. Please wait untill I find it.
Homepage (pl_PL): http://uzytkownik.jogger.pl/
(GNU/)Linux User: #425935 (see http://counter.li.org/)
Phlip (Guest)
on 2007-05-12 05:17
(Received via mailing list)
Maciej P. wrote:

> I'd like to use on browsers supporting AJAX link_to_remote or
> button_to_function/remote_function and on rest button_to and link_to.
>
> How can I determine it?

Send both systems, and let the browser figure it out, like this:

  <noscript>
    <%= my manual buttons %>
  </noscript>

  <%= javascript_tag ... %>

A browser without JavaScript will render the HTML inside <noscript>, so
put
your buttons there. And only a browser _with_ JavaScript will respect
the
<script> tags that javascript_tag inserts, so I suspect you could put
'document.write' calls in there that insert your link_to_remote tags.

/Pragmatic Ajax/ has a great section on degradability, but I don't know
if
it has the <noscript> trick.

--
  Phlip
  http://www.oreilly.com/catalog/9780596510657/
  "Test Driven Ajax (on Rails)"
  assert_xpath, assert_javascript, & assert_ajax
Maciej P. (Guest)
on 2007-05-12 12:03
(Received via mailing list)
On Fri, 11 May 2007 18:16:32 -0700, Phlip wrote:

>     <%= my manual buttons %>
> /Pragmatic Ajax/ has a great section on degradability, but I don't know
> if it has the <noscript> trick.

Thank you - sometimes I forget about those base (x)html tricks...

Regards
--
I've probably left my head... somewhere. Please wait untill I find it.
Homepage (pl_PL): http://uzytkownik.jogger.pl/
(GNU/)Linux User: #425935 (see http://counter.li.org/)
Alain R. (Guest)
on 2007-05-12 14:35
(Received via mailing list)
Maciej,

  > I'd like to use on browsers supporting AJAX link_to_remote or
  > button_to_function/remote_function and on rest button_to and
link_to.

link_to_remote offers fallback for js-challenged browsers, so this
code would do what you need :(untested)

  <%= link_to_remote "Delete",
    {:url   => {:action => "delete", :id => id} },      ## <-- if JS
available
    {:href  => url_for(:action => "delete",:id => id)}  ## <- if NO JS
  %>


, and in the controller you'd use 'respond_to' to handle both calls
within one action.



Alain R.
--------
blog.ravet.com/
Maciej P. (Guest)
on 2007-05-12 19:01
(Received via mailing list)
On Sat, 12 May 2007 12:33:56 +0200, Alain R. wrote:

>     {:url   => {:action => "delete", :id => id} },      ## <-- if JS
> Alain R.
Thanks. That is just what I wanted.

Regards

--
I've probably left my head... somewhere. Please wait untill I find it.
Homepage (pl_PL): http://uzytkownik.jogger.pl/
(GNU/)Linux User: #425935 (see http://counter.li.org/)
This topic is locked and can not be replied to.