Forum: Ruby on Rails No javascript fallback

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Jules J. (Guest)
on 2005-12-17 18:11
AJAX is good for a lot of things, but javascript is not always

I think the new RJS templates are very good:

And they could be used to create a simple, automatic no javascript
fallback. An example:

You have a controller called PostsController. There is an action "new".
The view displays a form. The form will be submitted to the
"create"-action using AJAX, and if the user doesn't have javascript
enabled, it will be submitted to the create action anyway. It looks like

class PostsController < ApplicationController
  def create
    @post =[:post])

This creates a new post. There are two views: one create.rhtml and one
create.rjs. Create.rhtml is just usual ruby-html code and create.rjs
contains javascript code that will be executed. Rails determines which
template to use with request.xhr?. If this is an xmlhttprequest: render
create.rjs, else render create.rhtml.

Would it be possible to do this with an after filter? The filter checks
if there are two templates: #{action}.rjs and #{action}.rhtml and
renders the correct one.

I will need to change the view helpers too to add automatic ajax and non
ajax submit.

Is this a good idea? How could the view helpers be implemented?
This topic is locked and can not be replied to.