1
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
謝謝!