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 -- Posted via http://www.ruby-forum.com/.
Alex Young
2006-Jan-23 11:49 UTC
[Rails] DRY encoding conversion and onload ajax execution
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? -- Alex
Jan Foeh
2006-Jan-23 12:11 UTC
[Rails] Re: DRY encoding conversion and onload ajax execution
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 -- Posted via http://www.ruby-forum.com/.