1

2 つのモデル オファーと国があり、それらには何の関係もありませんが、新しいオファー フォームでは、オファーの国を選択するための選択タグが必要です。

これが私の新しいアクションです:

def new
    @countries = Country.all
    @offer = Offer.new
end

これが私の見解です

<%= form_for(@offer) do |f| %>
    <%= f.select @countries %> #I know this is wrong.
    <%= f.submit %>
<% end %>

何か案が。

ありがとう

4

1 に答える 1

1

オファーの国を選択する必要がある場合は、モデルに関係が必要であることを意味します。

class Offer < ActiveRecord::Base
  belongs_to :country
end

class Country < ActiveRecord::Base
  has_many :offers
end

意見:

<%= form_for :offer do |form| %>
  <%= form.collection_select :country_id, Country.all, :id, :name %>
  <%= form.submit %>
<% end %>

これがあなたの求めているものでない場合は、質問を絞り込んでください。

于 2013-07-09T21:37:30.143 に答える