を通して私は、私が何をしようとしている、使用方法:関係
を私の問題を説明してみましょうが、現在のユーザーがそのチーム(私のモデルのいずれか)のドロップダウンリストが表示されています(他のモデル)に参加したいチームを選ぶことができるようにする。ここで私はやって考えていた(そしてそうする失敗した)ものだ:
<%= form_for @new_team, :url => join_tournament_path do |f| %>
<%= f.collection_select :team_id, current_user.user_teams, team ids of user teams?, user teams names parameter i guess, include_blank: true %>
<%= f.submit %>
<% end %>
showアクションコントローラで選択した大会のショービューで
def show
@tournament = Tournament.find(params[:id])
@new_team = @tournament.teams_in_tournaments.build
end
私は思いますユーザーが選択したチームのチームIDと共にトーナメントIDを送信するフォームのように、すべてのものを節約するカスタムの「参加」コントローラアクションに送信します。
私は私は本当にf.collection_select作品(およびドキュメントは、私の場合には本当に便利ではなかった)どのように理解していないと思うので、うまくいけば、誰かが、解決の方向に私を指すことができ
(言い訳私の)経由で英語
EDIT:
私のモデルとの関係:
チーム:
class Team < ActiveRecord::Base
has_many :user_teams
has_many :users, :through => :user_teams
has_many :teams_in_tournaments
has_many :tournaments, :through => :teams_in_tournaments
belongs_to :team_leader, class_name: "User"
end
ユーザー:
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
has_many :user_teams
has_many :teams, :through => :user_teams
end
トーナメント:
class Tournament < ActiveRecord::Base
has_many :teams_in_tournaments
has_many :teams, :through => :teams_in_tournaments
belongs_to :organizer, class_name: "User"
end
UserTeam:
class UserTeam < ActiveRecord::Base
belongs_to :user
belongs_to :team
validates :team_id, :uniqueness => { :scope => :user_id }
end
TeamsInTournament:
class TeamsInTournament < ActiveRecord::Base
belongs_to :tournament
belongs_to :team
validates :team_id, :uniqueness => { :scope => :tournament_id }
end
すると、あなたが関係を投稿してくださいすることができ:uが、このようなものになるだろう唯一欠けているものは、IDのと、あなたの場合は
<option>
要素で出力するオブジェクトの名前を追加することで、途中でありますモデル間? –
既に投稿されています:) – user3758208