私はルビーに慣れていないので、思ったよりも少し遅くなります。Ruby 3.0で作業しています。作成したデータベース内のテーブルの 1 つで、主キーを「インデックス」ページに表示したいと考えています。私はこれを行うのに苦労しています。手動で id をインデックス ビューに入れましたが、「undefined method `venture_round_id'」と言い続けます。
これは、テーブルの index.html がどのように見えるかです。
<h1>Listing venture_rounds</h1>
<table>
<tr>
<th>id</th>
<th>company</th>
</tr>
<% @venture_rounds.each do |venture_round| %>
<tr>
<td><%= venture_round.venture_round_id %></td>
<td><%= venture_round.company_id %></td>
<td><% link_to 'show', venture_round %></td>
<td><%= link_to 'Edit', edit_venture_round_path(venture_round) %></td>
<td><%= link_to 'Destroy', venture_round, method: :delete, data: { confirm: 'Are you sure?' } %></td>
</tr>
<% end %>
</table>
「venture_round_id」と「id」を手動で入力しました。
これは、私のコントローラーがインデックスに対してどのように見えるかです:
def index
@venture_rounds = VentureRound.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @venture_rounds }
end
end
私はこの問題を 2 日間調査してきましたが、それについて多くを見つけることができませんでした。問題は、独自のテーブルのキーにアクセスすることに関係していると思います。Venture_round_id を外部キーとして使用するデータベース構造の他の部分は問題なく動作します。ポインタやヒントをいただければ幸いです。