Hi guys,
I really like RJS. I think they''ll replace partials in alot of
instances. Unfortunately, because they''re automatically used like
.rhtml and .rxml and are hard to specifically specify it makes it
messy to preserve fallbacks when using them. For instance, using
partials instead of rjs, my create method might look like:
def create
post = Post.new(params[:post])
...
if @request.xhr?
# render partial
else
# do other things and let the rhtml be rendered
end
end
Is there a way to do this with rjs? Really, I guess I''m looking for a
way to specify when I want to render an RJS template over another.
Thoughts?
Also, I''ll show the code that I think pertains so you can see what
might need to be changed.
Looking at the render code which controlls which template we go to...
def pick_template_extension(template_path)#:nodoc:
if match = delegate_template_exists?(template_path)
match.first
elsif erb_template_exists?(template_path):
''rhtml''
elsif builder_template_exists?(template_path): ''rxml''
elsif javascript_template_exists?(template_path): ''rjs''
else
raise ActionViewError, "No rhtml, rxml, rjs or delegate
template found for #{template_path}"
end
end
def render_file(template_path, use_full_path = true, local_assigns = {})
@first_render = template_path if @first_render.nil?
if use_full_path
template_extension = pick_template_extension(template_path)
template_file_name = full_template_path(template_path,
template_extension)
else
template_file_name = template_path
template_extension = template_path.split(''.'').last
end
template_source = nil # Don''t read the source until we know that
it is required
.......
end
With local_assigns at the end of the method definition it makes it
tough to allow for a variable to specify rjs templates or the like
which would be passed to pick_template_extension. There may be a
better way to modify the code to do this.
Kev