0
私はこのコード行を持っているレールのテーブルに参加しましたselect_tagselect_tagにアルファベット順に発注、
Friendshipsにはfriendsテーブルにリンクするfriendship_idがあります。私は、Webページ上の名前のリストを参照してください原因の関連作品
友情コントローラで
def name
self.friend.name
end
を使用して名前を呼びます。
私はしたいと思います:アルファベット順
の上部にある「...友人を選択し、」追加して、私は本当に発見していないことを
- 順序をまだ何か。 問題2の場合は、selected = nilを無駄に追加します。あなたの助けを事前に
おかげ
EDIT(ANSWER):
私は、コレクションがフェッチされた道をchaging終わった、と友人の代わりに、友情を探しました。
私のUserモデルで<%= select_tag :friend_id, options_from_collection_for_select(current_user.friends, "id", "name"), :prompt => 'Select a friend...', :id => 'thought_contact_select' %>
has_many :friends, :through => :friendships, :order => :name
私はちょうどその友人のために関連した友情とコントローラ
friendship = Friendship.find_by_user_id_and_friend_id(current_user.id, params[:friend_id])
番号2の問題を解決しました。しかし、Number 1の問題は機能しません。なぜなら、current_user.friendshipsを呼び出していて、名前がfriendsという3番目のテーブルにあるからです。エラー 'SQLite3 :: SQLException:no such column:name:SELECT" * FROM "friendships" where "friendships"。 "user_id" = 6 ORDER BY name DESC' – wachichornia
改訂の答えを確認してください。 – wrzasa