Trying to post a user's email address to a membership table in rails -
https://github.com/jtrinker/highlands
i'm building app allows user sign in , join group. when click on group , click 'join' user's email address posted memberships table , users have joined group saved.
i have user, group, , membership model. things got little hairy once added membership table.
models:
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 , :omniauthable devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable # setup accessible (or protected) attributes 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
groups#show:
<h1><%= @group.name %></h1> <h4><%= @group.location %></h4> <p><%= @group.description %></p> <%= link_to "join +", memberships_path(:user_email => user.email), :method => :post %>
i'm not sure need have user become member of group.
all code on github - https://github.com/jtrinker/highlands
thanks!
as see sending :post request groups#create action via link_to, can way:
create :join action in membership controller
def join # code here end
add route following code
resources :membership :join, via: :get end
it show return route like:
membership_join /membership/:membership_id/join(.:format) membership#join
than in view link join action membership_id
<%= link_to "join +", membership_join_path(:membership_id => @group.id) %>
Comments
Post a Comment