سؤال

I got such error after I globalized my app using globalize3 gem.Before that It worked fine. It is because of that I translated all categories in 3 different languages. And at this moment it can't find that category. Because I am using that category name inside link. So if there is 3 categories then each time it should correspond to that category. But it not. Here is my code.

My application layout

 <% @categs1.each do |categ|%>
    <li>  <%= link_to (categ.name), products_path(:category => categ.name)   %> </li>
 <%end%>

My routes file

  root :to => 'home#index'

devise_for :admin_users, ActiveAdmin::Devise.config
  ActiveAdmin.routes(self)

namespace :products do
  resources :categories do
    resources :products
  end
  resources :products, only: :index
end

match '/:locale' => 'home#index'
scope "(:locale)", :locale => /en|lv|ru/ do
 resources :products, :manufacturers, :categories, :news, :ActiveAdmin

*Products_controller*

 @categs1 =  Category.find(:conditions => { :id => [16,21,29,30] })

If you need additional code, please ask me. I am stuck here for two days already:(

هل كانت مفيدة؟

المحلول

You can use where like following to get your desired result.

In your ProductsController:

@categs1 =  Category.where({ :id => [16,21,29,30] })

or if you'd like to stick to find then use this:

@categs1 =  Category.find(:all, :conditions => { :id => [16,21,29,30] })
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top