I want to load a form only if javascript is enabled.
I was hoping to do it like this:
<% if javascript_enabled? %>
...form code...
<% else %>
Please enable javascript
<% end %>
Is something like this possible?
I want to load a form only if javascript is enabled.
I was hoping to do it like this:
<% if javascript_enabled? %>
...form code...
<% else %>
Please enable javascript
<% end %>
Is something like this possible?
The problem with your approach is that only the browser knows if Javascript is enabled or not, and you try to check if is is enabled with rails (which is server interpreted code). There are several workarounds to solve this problem, but I usually do the following in my Rails apps:
<noscript>Please enable Javascript</noscript>
at the top of the page content.display:none
or visibility:hidden
attribute style in the form you want to show only when Javascript is enabled.This way your form is only showed when Javascript is enabled and the message requesting to enable Javascript is showed only when Javascript is not enabled.
Finally, you can use Rails code to make all this as simple as possible, of course.