3
私は初心者の方が多すぎるが、他の関連する回答者はいないと申し訳ありません。HABTM関係のIDの代わりに名前を表示
idの代わりにリンクが属するカテゴリ名を表示したいとします。
ここで移行します。
class CreateCategoriesLinks < ActiveRecord::Migration
def self.up
create_table :categories_links, :id => false do |t|
t.references :category
t.references :link
end
end
def self.down
drop_table :categories_links
end
エンド
カテゴリモデル
class Category < ActiveRecord::Base
has_and_belongs_to_many :links
end
class Link < ActiveRecord::Base
has_and_belongs_to_many :categories
end
そして、ここでは、インデックスの下にあるリンクコントローラでだと
を示したものだリンクモデルここにインデックスの内容がありますが、私はこれを見つけることができるすべての順列を試しました。
<%= link.category.name %>
<%= link.category_ids %>
を入力すると、IDが表示されます。
ありがとう!出来た! – Thomas