Sha256: c0a3c2a10deb555a9c4d2b666fdab445e4f33792f4fe94f99dcafd3bed062c7f
Contents?: true
Size: 1.2 KB
Versions: 4
Compression:
Stored size: 1.2 KB
Contents
class Admin::MembershipsController < ApplicationController before_filter :find_reader_and_group def index redirect_to admin_group_url(@group) end def create @membership = Membership.find_or_create_by_reader_id_and_group_id(@reader.id, @group.id) respond_to do |format| format.html { flash[:notice] = "#{@reader.name} added to group #{@group.name}" redirect_to admin_group_url(@group) } format.js { render :partial => 'reader' } end end def destroy @membership ||= @group.memberships.find(params[:id]) @reader = @membership.reader @membership.delete if @membership respond_to do |format| format.html { flash[:notice] = "#{@reader.name} removed from group #{@group.name}" if @membership redirect_to admin_group_url(@group) } format.js { render :partial => 'reader' } end end def toggle if @membership = Membership.find_by_reader_id_and_group_id(@reader.id, @group.id) destroy else create end end protected def find_reader_and_group @group = Group.find(params[:group_id]) @reader = Reader.find(params[:reader_id]) if params[:reader_id] end end
Version data entries
4 entries across 4 versions & 1 rubygems