AR finder with include only specific value

i have a model :user with an association has_many :langs.

table langs have fields title and langcode.

In practice every users have many langs, i retrieve specific lang with
the langcode (en, de, fr, it, es, etc.)

Now i want to display list users with the only default lang (en), i have
used this query:

@users = User.find(:all, :include => :langs)

and on wiew this:

<% for item in @users %>

<%=h item.langs.first.title %> <%=h item.langs.first.langcode %> <% end %>

but this don’t display selected items by default value langcode (“en”).
how can i select only the “en” langcode from my query?

i have tryed with :

@users = User.find(:all, :include => :langs, , :conditions =>
[‘langs.langcode = ?’, “en”])

but never happen.

finally i solved with this:

@users = User.find(:all, :include => :langs)

and on wiew modified with:

<%=h item.langs.find_by_langcode(I18n.default_locale.to_s).title %> <%=h item.langs.find_by_langcode(I18n.default_locale.to_s).langcode %>

this solution work, i hope right also in terms of performances

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs