Bill Walton
2006-Aug-30 18:26 UTC
respond_to not detecting JS turned on. form_to_remote problem?
I''m trying to use respond_to to redirect visitors who have JS turned
off to a different page. The problem I''m having is that respond_to is
sending *everybody* there. It''s not recognizing that JS is turned on
in the browser. The wanted_html.rhtml file below is rendered whether
I''ve got JS turned on or off. I''ve looked at the Accept
headers being sent from the form_remote_tag button using Live HTTP Headers. The
headers are exactly the same whether JS is turned on or off. That seems wierd.
Another wierd thing. When the form is submitted, in the Firebug console, I see
a POST, then it disappears. I put the sleep() call in below to verify. The
POST is there until the respond_to is evaluated. Then the POST disappears from
the console. Any ideas? I''ll post the code below. TIA.
Bill
----- Controller -----
class CreateController < ApplicationController
def index
end
def edit
sleep(5)
respond_to do |wants|
wants.html { redirect_to :action => ''wanted_html'' }
wants.js { render }
end
end
def wanted_html
end
end
----- Views -----
--- index.rhtml ---
<p>Click the button to test the respond_to method</p>
<%= form_remote_tag :url => {:action => ''edit''} %>
<div>
<%= submit_tag ''Test'', :disable_with => "Please
Wait" %>
</div>
<%= end_form_tag %>
--- edit.rjs ---
page.alert "You made it with JS turned on!"
--- wanted_html.rhtml ---
respond_to says you don''t have JS turned on.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---
Curtis Summers
2006-Aug-30 21:00 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Bill Walton wrote:> I''m trying to use respond_to to redirect visitors who have JS turned off > to a different page. The problem I''m having is that respond_to is > sending *everybody* there.I noticed a similar problem in an application I''m building. I tried to use respond_to but it did not consistently work. However, testing for request.xhr? works correctly everytime for me. def edit if request.xhr? render else redirect_to :action => ''wanted_html'' end end You might read through this thread for more information: http://lists.rubyonrails.org/pipermail/rails/2006-June/049284.html -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Aug-30 22:44 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Hi Curtis, Thanks for your response! Curtis Summers> I noticed a similar problem in an application I''m building. I tried to > use respond_to but it did not consistently work. However, testing for > request.xhr? works correctly everytime for me.I tried the code you suggested and it didn''t work either. Then I eliminated the ''if'' and just tried to see if RJS was working. I think there''s something wrong with my setup. I changed the controller so all the actions are empty and just call their views. The edit.rjs file contains just one line: page.alert "you have JS turned on" What gets displayed is, rather than the dialog I expected, I get an html page that displays (rather than executes) the JS that Rails sent back. try { alert("you have JS turned ON"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''alert(\"you have JS turned ON\");''); throw e } Any idea what might be causing this? Thanks, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Ezra Zygmuntowicz
2006-Aug-31 01:01 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
On Aug 30, 2006, at 3:44 PM, Bill Walton wrote:> > Hi Curtis, > > Thanks for your response! > > Curtis Summers > >> I noticed a similar problem in an application I''m building. I >> tried to >> use respond_to but it did not consistently work. However, testing >> for >> request.xhr? works correctly everytime for me. > > I tried the code you suggested and it didn''t work either. Then I > eliminated > the ''if'' and just tried to see if RJS was working. I think there''s > something wrong with my setup. > > I changed the controller so all the actions are empty and just call > their > views. The edit.rjs file contains just one line: > page.alert "you have JS turned on" > > What gets displayed is, rather than the dialog I expected, I get an > html > page that displays (rather than executes) the JS that Rails sent back. > > try { > alert("you have JS turned ON"); > } > catch (e) { > alert(''RJS error:\n\n'' + e.toString()); > alert(''alert(\"you have JS turned ON\");''); > throw e } > > Any idea what might be causing this? > > Thanks, > BillDid you remember to do <%= javascript_include_tag :defaults %> in the layout? -Ezra --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Aug-31 02:22 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Hi Ezra, Ezra Zygmuntowicz wrote:> Did you remember to do <%= javascript_include_tag > :defaults %> in the layout?Yes. And this is a test (i.e., tiny) app. I''ve included all the code below. I"m also going to try tomorrow and see is there''s any chance this is a dev vs. prod issue. Any insight you could provide will be hugely appreciated. Just fyi, I''m developing / seeing the problem on WinXP, SP2. I don''t understand the behavior I''m seeing. I manually check to make sure JS is enabled. It is. I click the button on the index page, which should render edit.rjs and throw up a message dialog. I get the following JS rendered instead. try { alert("you have JS turned ON"); } catch (e) { alert(''RJS error:\n\n'' + e.toString()); alert(''alert(\"you have JS turned ON\");''); throw e }This is startin'' to ... Any insight will be grounds for worship ;-) Thanks, Bill ----- controller ----- class CreateController < ApplicationController def index end def edit end def wanted_html end end ----------------- ----- views ----- ----------------- --- application.rhtml --- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> <html> <head> <%= javascript_include_tag :defaults %> </head> <body> <%= yield %> </body> </html> --- index.rhtml --- <p>Click the button to test the respond_to method</p> <%= form_remote_tag(:url => {:action => ''edit''}) %> <div> <%= submit_tag ''Test'', :disable_with => "Please Wait" %> </div> <%= end_form_tag %> --- edit.rjs --- page.alert "you have JS turned ON" --- wanted_html.rhtml --- respond_to says you have JS turned OFF. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Łukasz Piestrzeniewicz
2006-Aug-31 06:47 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Bill Walton wrote:> I''m trying to use respond_to to redirect visitors who have JS turned off > to a different page.<snip />> def edit > sleep(5) > respond_to do |wants| > wants.html { redirect_to :action => ''wanted_html'' } > wants.js { render } > end > endLong shot, but have you tried to change order of wants.html and wants.js? def edit sleep(5) respond_to do |wants| wants.js { render } wants.html { redirect_to :action => ''wanted_html'' } end end Cheers, Bragi -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Aug-31 12:10 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Hi Lukasz, Łukasz Piestrzeniewicz wrote:> Long shot, but have you tried to change order > of wants.html and wants.js?Yep. Tried it. No joy. But thanks for the reply! Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Curtis Summers
2006-Aug-31 12:38 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Bill, The disable_with may be causing your problem due to a bug: http://dev.rubyonrails.org/ticket/5899 Take out the disable_with and see what happens. Curtis -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org
2006-Aug-31 12:44 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Hi -- On Thu, 31 Aug 2006, Bill Walton wrote:> > Hi Lukasz, > > ukasz Piestrzeniewicz wrote: > >> Long shot, but have you tried to change order >> of wants.html and wants.js? > > Yep. Tried it. No joy. But thanks for the reply!I duplicated your problem and was able to solve it by removing the :disable_with option from the call to submit_tag. I''ll leave it to one of the resident JS guri to explain exactly why, but I assume it has something to do with the JS generated by submit_tag. David -- David A. Black | dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org Author of "Ruby for Rails" [1] | Ruby/Rails training & consultancy [3] DABlog (DAB''s Weblog) [2] | Co-director, Ruby Central, Inc. [4] [1] http://www.manning.com/black | [3] http://www.rubypowerandlight.com [2] http://dablog.rubypal.com | [4] http://www.rubycentral.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Aug-31 16:49 UTC
Re: respond_to not detecting JS turned on. form_to_remote p
Hi David, Curtis; dblack-TKXtfPMJ4Ozk1uMJSBkQmQ@public.gmane.org wrote:> I duplicated your problem and was able to > solve it by removing the:disable_with option > from the call to submit_tag.Curtis Summers wrote:> The disable_with may be causing your problem > due to a bug:Thank you both very much!!! That was it. It never would have occurred to me to try that. Even reading the bug ticket didn''t spark an ''aha'' since I''m not doing any form processing. At any rate, removing the "disable_with" option fixed the problem completely. I''ll send another email to post the code for future readers. Best regards to you both, Bill --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk -~----------~----~----~----~------~----~------~--~---
Bill Walton
2006-Aug-31 17:07 UTC
RESOLVED: [Rails] respond_to not detecting JS turned on. form_to_remote problem?
Thanks to David Black and Curtis Summers for identifying the problem: DO NOT use
the :disable_with option on the submit_tag for form_remote_tag, at least not
until http://dev.rubyonrails.org/ticket/5899 is closed.
The code below the original post is a complete working app that demonstrates the
use of respond_to for redirecting non-JS- and JS-enabled browsers to different
pages. I''ve left the original posting to assist future
Railers'' searches.
----- Original Message -----
From: Bill Walton
To: rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
Sent: Wednesday, August 30, 2006 1:26 PM
Subject: [Rails] respond_to not detecting JS turned on. form_to_remote
problem?
I''m trying to use respond_to to redirect visitors who have JS turned
off to a different page. The problem I''m having is that respond_to is
sending *everybody* there. It''s not recognizing that JS is turned on
in the browser. The wanted_html.rhtml file below is rendered whether
I''ve got JS turned on or off. I''ve looked at the Accept
headers being sent from the form_remote_tag button using Live HTTP Headers. The
headers are exactly the same whether JS is turned on or off. That seems wierd.
Another wierd thing. When the form is submitted, in the Firebug console, I
see a POST, then it disappears. I put the sleep() call in below to verify. The
POST is there until the respond_to is evaluated. Then the POST disappears from
the console. Any ideas? I''ll post the code below. TIA.
---- Controller ----
class CreateController < ApplicationController
def index
end
def edit
respond_to do |wants|
wants.html { redirect_to :action => ''js_inactive'' }
wants.js {
render :update do |page|
page.redirect_to :action => ''js_active''
end
}
end
end
def js_active
end
def js_inactive
end
end
---- index.rhtml -----
<p>Click the button to test if JS is activated.</p>
<%= form_remote_tag(:url => {:action => ''edit''})
%>
<div>
<%= submit_tag ''Test for JS'' %>
</div>
<%= end_form_tag %>
---- js_active.rhtml ----
<div>
<%=h( "Your system has JS activated" )%>
</div>
---- js_inactive.rhtml ----
<div>
<%=h( "Your system does NOT have JS activated" )%>
</div>
---- application.rhtml ----
<html>
<head>
<%= javascript_include_tag :defaults %>
</head>
<body>
<%= @content_for_layout %>
</body>
</html>
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk
-~----------~----~----~----~------~----~------~--~---