Forum: Ruby on Rails a RJS problem/patch

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2006-01-30 18:13
(Received via mailing list)
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/HowtoSetDe...

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
2ccb2f7699267d258faaafce4ee997df?d=identicon&s=25 Cody Fauser (Guest)
on 2006-01-30 20:12
(Received via mailing list)
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 Mutoh <mutoh@highway.ne.jp> wrote:
>   end
> -              "@controller.headers['Content-Type'] ||= 'text/xml'\n" +
> actionpack/lib/action_view/base.rb seems to have same problem.
>              when :rjs
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>


--
Cody Fauser
http://www.codyfauser.com
821395fe70906c8290df7f18ac4ac6cf?d=identicon&s=25 Rick Olson (Guest)
on 2006-01-30 21:46
(Received via mailing list)
> 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 Olson
http://techno-weenie.net
C004d67820a114e24ccf6f2ddaf5b236?d=identicon&s=25 Richard Livsey (Guest)
on 2006-01-30 21:46
(Received via mailing list)
Rick Olson 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/HowtoSetDe...
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2006-01-31 00:45
(Received via mailing list)
Hi,

On Mon, 30 Jan 2006 14:10:51 -0500
Cody Fauser <codyfauser@gmail.com> 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.
9fe908f5593444a40be14a424c372e58?d=identicon&s=25 Masao Mutoh (Guest)
on 2006-01-31 00:54
(Received via mailing list)
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
This topic is locked and can not be replied to.