Note that there are some explanatory texts on larger screens.

plurals
  1. POTranslating model with Globalize2 (rails)
    primarykey
    data
    text
    <p>I’m using latest globalize2 and rails 2.2. I wonder if the following is bug or feature: there seems to be a separate db query for each item in a dataset to get the translation. That doesn’t sound right since it may easily result in hundreds of queries.</p> <p>Illustration. Simple controller:</p> <pre><code>def index @menu_sections = MenuSection.find(:all) end </code></pre> <p>Then @menu_sections is looped thru in a view, where localized attribute (name) is called:</p> <pre><code> &lt;% @menu_sections.each do |menu_section| %&gt; &lt;p&gt;&lt;%= link_to menu_section.name, :controller =&gt; 'store', :action =&gt; 'list_menu_items_for_section', :section_id =&gt; menu_section.id %&gt;&lt;/p&gt; &lt;% end %&gt; </code></pre> <p>Looks like every menu_section.name results in db query:</p> <pre> Processing StoreController#index (for 10.0.2.2 at 2009-03-02 16:05:53) [GET] Session ID: 468f54928cbdc0b19c03cfbd01d09fa9 Parameters: {"action"=>"index", "controller"=>"store"} MenuSection Load (0.0ms) SELECT * FROM `menu_sections` Rendering template within layouts/store Rendering store/index Rendered application/_js_includes (0.0ms) MenuSection Columns (0.0ms) SHOW FIELDS FROM `menu_sections` MenuSectionTranslation Load (0.0ms) SELECT * FROM `menu_section_translations` WHERE (`menu_section_translations`.menu_section_id = 1 AND (`menu_section_translations`.`locale` IN ('en','root'))) MenuSectionTranslation Columns (0.0ms) SHOW FIELDS FROM `menu_section_translations` MenuSectionTranslation Load (0.0ms) SELECT * FROM `menu_section_translations` WHERE (`menu_section_translations`.menu_section_id = 2 AND (`menu_section_translations`.`locale` IN ('en','root'))) MenuSectionTranslation Load (0.0ms) SELECT * FROM `menu_section_translations` WHERE (`menu_section_translations`.menu_section_id = 3 AND (`menu_section_translations`.`locale` IN ('en','root'))) Completed in 340ms (View: 320, DB: 0) | 200 OK [http://www.dev.babooka.com/store] </pre> <p>What do you think? Perhaps there is a better way for translating db data in rails?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload