A RJS problem/patch


#1

Hi,

add_rjs_to_action_view.rb of javascript_generator_templates
doesn’t work with setting Content-Type in a controller.
(e.g.) http://wiki.rubyonrails.org/rails/pages/HowtoSetDefaultEncoding

class ApplicationController < ActionController::Base
before_filter :set_charset
def set_charset
@headers[“Content-Type”] = “text/html; charset=utf-8”
end
end

I think it’s better to set it forcely.

— add_rjs_to_action_view.rb.old 2006-01-31 01:42:59.000000000
+0900
+++ add_rjs_to_action_view.rb 2006-01-31 01:43:29.000000000 +0900
@@ -50,10 +50,10 @@
body = case extension.to_sym
when :rxml
“xml = Builder::XmlMarkup.new(:indent => 2)\n” +

  •          "@controller.headers['Content-Type'] ||= 'text/xml'\n" +
    
  •          "@controller.headers['Content-Type'] = 'text/xml'\n" +
             template
           when :rjs
    
  •          "@controller.headers['Content-Type'] ||= 
    

‘text/javascript’\n" +

  •          "@controller.headers['Content-Type'] = 
    

‘text/javascript’\n" +
“update_page do |page|\n#{template}\nend”
end
else

I haven’t try CVS version of rails yet, but
actionpack/lib/action_view/base.rb seems to have same problem.

— base.rb.old 2006-01-31 02:05:28.000000000 +0900
+++ base.rb 2006-01-31 02:05:38.000000000 +0900
@@ -394,10 +394,10 @@
body = case extension.to_sym
when :rxml
“xml = Builder::XmlMarkup.new(:indent => 2)\n” +

  •          "@controller.headers['Content-Type'] ||= 'text/xml'\n" +
    
  •          "@controller.headers['Content-Type'] = 'text/xml'\n" +
             template
           when :rjs
    
  •          "@controller.headers['Content-Type'] ||= 
    

‘text/javascript’\n" +

  •          "@controller.headers['Content-Type'] = 
    

‘text/javascript’\n" +
“update_page do |page|\n#{template}\nend”
end
else


#2

Masao,

The RJS plugin is created directly from the Rails trunk, but isn’t
supported by the Rails core team. This means that you’ll have to make
your patch against the Rails trunk by checking out Edge Rails from the
svn repository. Then you can make a ticket at
http://dev.rubyonrails.org with your patch and if your change is
accepted there it will also be added to the plugin.

On 1/30/06, Masao M. removed_email_address@domain.invalid wrote:

end

  •          "@controller.headers['Content-Type'] ||= 'text/xml'\n" +
    

actionpack/lib/action_view/base.rb seems to have same problem.
when :rjs
removed_email_address@domain.invalid
http://lists.rubyonrails.org/mailman/listinfo/rails


Cody F.
http://www.codyfauser.com


#3

class ApplicationController < ActionController::Base
before_filter :set_charset
def set_charset
@headers[“Content-Type”] = “text/html; charset=utf-8”
end
end

before_filter :set_charset, :except => [:rjs]


Rick O.
http://techno-weenie.net


#4

Hi,

On Mon, 30 Jan 2006 14:10:51 -0500
Cody F. removed_email_address@domain.invalid wrote:

Masao,

The RJS plugin is created directly from the Rails trunk, but isn’t
supported by the Rails core team. This means that you’ll have to make
your patch against the Rails trunk by checking out Edge Rails from the
svn repository. Then you can make a ticket at
http://dev.rubyonrails.org with your patch and if your change is
accepted there it will also be added to the plugin.

Thanks. I’ll post it there, again.


#5

Rick O. wrote:

class ApplicationController < ActionController::Base
before_filter :set_charset
def set_charset
@headers[“Content-Type”] = “text/html; charset=utf-8”
end
end

before_filter :set_charset, :except => [:rjs]

Alternatively:

class ApplicationController < ActionController::Base
after_filter :set_charset

def set_charset
@headers[“Content-Type”] ||= “text/html; charset=utf-8”
end
end

I’ve mentioned this on the wiki page too:
http://wiki.rubyonrails.org/rails/pages/HowtoSetDefaultEncoding


#6

Rick, Richard,

Thanks for your information.

But I think it’s better it doesn’t have an effect
to application side.

On Mon, 30 Jan 2006 19:50:58 +0000