我使用了rails globalize和I18n gem。但現在我無法分類我的模型。你們能幫忙嗎?無法通過欄目索引
我嘗試添加一個新的索引,但我不完全熟悉的索引。
Controller.rb
def index
@foods = Food.all.order(:name)
add_breadcrumb "index", foods_path
end
架構
create_table "food_translations", force: :cascade do |t|
t.integer "food_id", null: false
t.string "locale", null: false
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "name"
t.string "bio"
end
add_index "food_translations", ["food_id"], name: "index_food_translations_on_food_id", using: :btree
add_index "food_translations", ["locale"], name: "index_food_translations_on_locale", using: :btree
add_index "food_translations", ["name"], name: "index_food_translations_on_name", using: :btree
create_table "foods", force: :cascade do |t|
t.string "address"
t.string "phone"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.string "image_file_name"
t.string "image_content_type"
t.integer "image_file_size"
t.datetime "image_updated_at"
t.string "yelp"
t.string "youtube"
end
'name'是FoodTranslation'的'屬性,而不是'Food'。你沒有在那裏顯示任何關係,但你需要以某種方式包含'food_translations'表,以便能夠對'food_translations.name'進行排序。 – Amadan
我明白了。我嘗試加入(FoodTranslations.name),但語法肯定是錯誤的。 –
問題是,你應該在你的問題中包含你的模型類以及相關的關聯(比如'belongs_to')。 – Amadan