https://github.com/jtrinker/highlands
ユーザーがサインインしてグループに参加できるアプリを作成しています。グループをクリックしてから「参加」をクリックすると、ユーザーの電子メールアドレスがメンバーシップテーブルに投稿され、そのグループに参加したユーザーが保存されます。
ユーザー、グループ、およびメンバーシップ モデルがあります。メンバーシップ テーブルを追加すると、少し複雑になりました。
モデル:
class Membership < ActiveRecord::Base
belongs_to :user
belongs_to :group
attr_accessible :user_email
end
class User < ActiveRecord::Base
belongs_to :group
# Include default devise modules. Others available are:
# :token_authenticatable, :confirmable,
# :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :email, :username, :password, :password_confirmation, :remember_me
end
class Group < ActiveRecord::Base
has_many :memberships
has_many :users, :through => :memberships
attr_accessible :description, :location, :name
end
グループ#表示:
<h1><%= @group.name %></h1>
<h4><%= @group.location %></h4>
<p><%= @group.description %></p>
<%= link_to "Join +", memberships_path(:user_email => user.email), :method => :post %>
ユーザーをグループのメンバーにするために何をする必要があるのか わかりません。
私のコードはすべて github にアップされています - https://github.com/jtrinker/highlands
ありがとう!