Javascript disabled?

Hi,

I’d like to know what’s the best way to find out in RoR if the user’s
browser has javascript turned off. I know some of you may yell at me for
not degrading but my application must have JS on and I’d like to
redirect and display a “sorry” message if JS is off. I saw some posts
regarding using tag. is that the way to go?

thanks!
Alan.

Hi Alan,

Alan wrote:

I’d like to know what’s the best way to
find out in RoR if the user’s browser has
javascript turned off.

I’ve got a situation I’m handling exactly the same way. In the
controller:

def check_js
respond_to do |wants|
wants.html {redirect_to :action => ‘sorry’}
wants.js {
render :update do |page|
page.redirect_to :controller => ‘actor’, :action =>
‘edit_patient’
end
}
end
end

It’s important that the responses be in line with the request. So the
html
branch needs to respond with html, and the js branch needs to respond
with
js. You can use an RJS view, or do the render in the controller like
above.
But you can’t render html in the wants.js response or the respond_to
won’t
work.

hth,
Bill

Bill W. wrote:

Hi Alan,

Alan wrote:

I’d like to know what’s the best way to
find out in RoR if the user’s browser has
javascript turned off.

I’ve got a situation I’m handling exactly the same way. In the
controller:

def check_js
respond_to do |wants|
wants.html {redirect_to :action => ‘sorry’}
wants.js {
render :update do |page|
page.redirect_to :controller => ‘actor’, :action =>
‘edit_patient’
end
}
end
end

It’s important that the responses be in line with the request. So the
html
branch needs to respond with html, and the js branch needs to respond
with
js. You can use an RJS view, or do the render in the controller like
above.
But you can’t render html in the wants.js response or the respond_to
won’t
work.

hth,
Bill

thanks Bill! That’s a nice solution, I haven’t even known about the
existance of “respond_to” before your answer. I’m going to read some
more about it but what I’m looking for is a method which could be used
as a ‘before filter’ in application.rb so that the “sorry, must have
javascript” page will be redirected to upon entry from any page of my
site if JS is disabled. I’m wondering if this method above will work for
this scenario…

Alan

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs