No javascript fallback

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 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