Forum: Ruby on Rails DRY encoding conversion and onload ajax execution

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.
C656c8b5f358a6f8597f0d5cf52a9597?d=identicon&s=25 Jan Foeh (Guest)
on 2006-01-23 12:35
Hi everybody,

my first Rails app is a frontend for customer data pulled from a legacy
postgres database. The db is encoded in Latin1, but my pages will be
UTF-8.

What is the best way of character encoding conversion? I haven't found
any way to have Rails deal with this natively, so I assume I have to
take care of this myself, right?

Where would I place my conversion code if I want to honor DRY?

Another thing is I'm wondering how to have AJAX actions executed
automatically on page load? What I am trying to achieve is having a view
which only consists of some container divs which are populated via AJAX
immediately after the page loads, without the user having to click on
something.

Thanks to all in advance for any help!

- Jan
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (Guest)
on 2006-01-23 12:50
(Received via mailing list)
Jan Foeh wrote:
> Hi everybody,
>
> my first Rails app is a frontend for customer data pulled from a legacy
> postgres database. The db is encoded in Latin1, but my pages will be
> UTF-8.
>
> What is the best way of character encoding conversion? I haven't found
> any way to have Rails deal with this natively, so I assume I have to
> take care of this myself, right?
Yup.  The Iconv library is what you want to look for.  Works a treat.

> Where would I place my conversion code if I want to honor DRY?
You've got two options:  either a callback in the model, or an h()-style
view helper.  It's not really where it should be from an MVC
perspective, but I'd put it in the model - that way there's less chance
of forgetting to convert it in the view.  A mixin would seem to be the
natural way to do it.

> Another thing is I'm wondering how to have AJAX actions executed
> automatically on page load? What I am trying to achieve is having a view
> which only consists of some container divs which are populated via AJAX
> immediately after the page loads, without the user having to click on
> something.
Use the window.onLoad() event?
C656c8b5f358a6f8597f0d5cf52a9597?d=identicon&s=25 Jan Foeh (Guest)
on 2006-01-23 13:11
Alex Young wrote:

>> Where would I place my conversion code if I want to honor DRY?
> You've got two options:  either a callback in the model, or an h()-style
> view helper.  It's not really where it should be from an MVC
> perspective, but I'd put it in the model - that way there's less chance
> of forgetting to convert it in the view.  A mixin would seem to be the
> natural way to do it.

Thanks Alex! I'll have a look at mixins then; this seems to be exactly
what I was searching for.

>> Another thing is I'm wondering how to have AJAX actions executed
>> automatically on page load? What I am trying to achieve is having a view
>> which only consists of some container divs which are populated via AJAX
>> immediately after the page loads, without the user having to click on
>> something.
> Use the window.onLoad() event?

I was wondering if there was a Rails-way to achieve this which I had
overlooked; I'll take that as a 'no' :)

Thanks again!
- Jan
This topic is locked and can not be replied to.