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
谢谢!