RJS Templates
I love RJS. It means I don't have to wade through Javascript (yeuch). But RJS templates have been bothering me for a while. You see your .rhtml and your .mab files literally are views. They define HTML as it appears on-screen. But your .rjs files are not. They manipulate what is there but they do not define it. The proof of this is when you find yourself writing:
page.replace_html 'something', :partial => 'something', :object => @something
The RJS defines what you want to happen to the page but what actually gets displayed is in _something.mab (or _something.rhtml).
So I have decided to do the following from now on: no more .rjs "views" - instead I will code my controllers like this:
def new
@something = Something.new
respond_to do | format |
format.js { render_new_as_js }
end
end
private
def render_new_as_js
render :update do | page |
page.replace_html 'something', :partial => 'something', :object => @something
page.visual_effect :highlight, 'something'
end
end
In other words code stays in the controller and html stays in the views.
No comments:
Post a Comment