# A RJS problem/patch

**URL:** <https://www.ruby-forum.com/t/a-rjs-problem-patch/98925>\
**Category:** Rails\
**Created:** [January 30, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925 "2006-01-30T18:13:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Masao\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@Masao\_M](https://www.ruby-forum.com/u/Masao_M)\
**Post date:** [January 30, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925/1 "2006-01-30T18:13:39Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Masao\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@Masao\_M](https://www.ruby-forum.com/u/Masao_M)\
**Post date:** [January 30, 2006, 8:12pm UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925/2 "2006-01-30T20:12:11Z")

</div>

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](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](mailto: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](http://lists.rubyonrails.org/mailman/listinfo/rails)

–  
Cody F.  
[http://www.codyfauser.com](http://www.codyfauser.com)

---

<div class="post-metadata">

**Author:** ![Masao\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@Masao\_M](https://www.ruby-forum.com/u/Masao_M)\
**Post date:** [January 30, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925/3 "2006-01-30T21:46:49Z")

</div>

> 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](http://techno-weenie.net)

---

<div class="post-metadata">

**Author:** ![Masao\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@Masao\_M](https://www.ruby-forum.com/u/Masao_M)\
**Post date:** [January 31, 2006, 12:45am UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925/4 "2006-01-31T00:45:50Z")

</div>

Hi,

On Mon, 30 Jan 2006 14:10:51 -0500  
Cody F. [removed\_email\_address@domain.invalid](mailto: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](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.

---

<div class="post-metadata">

**Author:** ![Masao\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@Masao\_M](https://www.ruby-forum.com/u/Masao_M)\
**Post date:** [January 30, 2006, 9:46pm UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925/5 "2006-01-30T21:46:52Z")

</div>

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](http://wiki.rubyonrails.org/rails/pages/HowtoSetDefaultEncoding)

---

<div class="post-metadata">

**Author:** ![Masao\_M](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/839c29/32.png) [@Masao\_M](https://www.ruby-forum.com/u/Masao_M)\
**Post date:** [January 31, 2006, 12:54am UTC](https://www.ruby-forum.com/t/a-rjs-problem-patch/98925/6 "2006-01-31T00:54:54Z")

</div>

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
