tm762108
@tm762108 (t m)

Are you sure you want to delete the question?

If your question is resolved, you may close it.

Leaving a resolved question undeleted may help others!

We hope you find it useful!

一覧にIDに紐づくnameを表示したい

content_tagを使ってアイテム一覧を表示しているのですが、アイテムに紐づくステータスはstatus.rbで管理しています。

class  Status < ActiveHash::Base
  self.data = [
      {id: 1, name: '新規'}, 
      {id: 2, name: '収納済み'}, 
      {id: 3, name: '要保存'},
      {id: 4, name: '処分検討'},
      {id: 5, name: '要処分'},
      {id: 6, name: '処分済み'}
  ]
end

この場合、アイテムテーブルにはステータスはIDで登録されているので、このままcontent_tagで表示をすると、数字でしか表示ができません。

        - @items.each.with_index(1) do |item, i|
          = content_tag :tr, class: 'image' do
            -#= item.item_images.each do |image|
              -#= content_tag :td, image_tag(image.image, :size => '50x60')
            = content_tag :td, link_to(item.name, item)
            = content_tag :td, item.strage_id
            = content_tag :td, item.status_id
            = content_tag :td, item.quantity
            = content_tag :td, item.limitation
            = content_tag :td, item.notes

IDに紐づくnameを一覧で表示させるにはどのようにすればいいのでしょうか?
どうぞよろしくお願いいたします。

0

1Answer

Your answer might help someone💌