私はこれがシンプルであるべきだと感じますが、問題を起こしてしまいました。私はHABTMを試しましたが、私はそれが私の必要と考えるものではありません。国has_manyチャンネルチェックボックスを選択
「国」has_many「チャネル」と「チャネル」は「国」に属します。基本的に私はチャンネルのフォームにチェックボックスのある国をリストし、country_idに国の配列を保存したいと思います。ここで
ビューです:
<%= f.label :country_id, "Countries" %><br />
<ul style="padding: 0; margin: 0;">
<% for country in Country.find(:all) %>
<li style="list-style: none;">
<%= check_box_tag "channel[country_ids][]", :name => "channel[country_ids][]" %>
<%= label_tag country.id, country.name %>
</li>
<% end %>
</ul>
country.rb
class Country < ActiveRecord::Base
has_many :channel
has_many :satellites
has_many :statistics
has_many :testimonies
has_many :videos
attr_accessible :name, :coords
def hash
name.gsub(" ", "_").downcase
end
end
channel.rb
class Channel < ActiveRecord::Base
belongs_to :countries
attr_accessible :name, :logo, :country_id
end
私は統計、衛星と同じことをやっているつもりです、証言、ビデオも同様です。
何か助けていただければ幸いです。ありがとう!
FYI私はRailsのでは2.3.8とRailsのない3
ね... "COUNTRY_ID諸国の配列を保存"? – tybro0103