Globalize and respond_to

Has anyone using globalize tried it with a respond_to in your
controller? Something like:

def show
@question = Question.find(1)
respond_to do |type|
type.html
type.xml
end
end

I started RESTifying my site and started using respond_to. I kept
getting an error saying that “show.rhtml” was not found, even though
it was there. If I removed the respond_to block then the show view
would output correctly. I tried all sorts of things trying to figure
out the problem - including changing servers many times from
webbrick, to mongrel inside of locomotive and then finally to
litespeed. None of that worked.

I know it was something local to my site because I set up a test app
and respond_to worked fine.

I started stripping out all the stuff to see if that would help and
that brought me to globalize. If I comment out all of the globalize
stuff, then my respond_to works fine.

I haven’t dug in to see what could be causing it within globalize,
but it definetely works without globalize and does not with globalize.

Has anyone else experienced this?

Thanks,
Steve

yes, I copy and paste here an email I sent about 3 weeks ago to the
globalize mailing list:


Hi,

I’m having problem with globalize (for-1.1, revision 199) and actionview
combined with MimeResponds.

This is my, hopefully not too wrong, analysis:

Responders in MimeResponds (
actionpack-1.12.5/lib/action_controller/mime_responds.rb
) work rendering a template_path that includes extension, for example
template.rxml, template.rhtml, etc.

ActionView::Base in globalize (
globalize/lib/globalize/rails/action_view.rb
) passes this kind of templates to pick_template_extension (line 29) and
this throws an exception.
To workaround this problem, one can borrow code from rails 1.1
ActionView::Base#render_file and substitute

if use_full_path
template_extension =
pick_template_extension(template_path).to_s
template_file_name = full_template_path(template_path,
template_extension)

with

if use_full_path
template_extension = nil
template_path_without_extension, template_extension =
path_and_extension(template_path)
if template_extension
template_file_name =
full_template_path(template_path_without_extension, template_extension)
else
template_extension =
pick_template_extension(template_path).to_s
template_file_name = full_template_path(template_path,
template_extension)
end

This works well in controllers but, unfortunately, completely breaks the
globalize action_mailer_test because of the content type “extensions”
added by globalize.
Example:
passed value → test.en.plain.text
expected template → test.en.plain.text.rhtml
but path_and_extension cuts text and search
test.en.plain.rhtml → exception.

What are your thoughts?
Thanks in advance.

Unfortunately nobody has replied :frowning: , anyway I suppose that you could
solve your problems with the proposed modifications in
globalize/lib/globalize/rails/action_view.rb

By the way, to work out the consequent problems with ActionMailer,
perhaps Globalize should use _ as separator, as gettext does (
http://www.yotabanana.com/hiki/ruby-gettext-howto-rails.html#Localized+templates+for+Views%2FActionMailer
)

Best regards