Sha256: fe337156b792480ae79c8fc2383231ea1bbade1ca105381002b725aa28939ee8

Contents?: true

Size: 1.7 KB

Versions: 8

Compression:

Stored size: 1.7 KB

Contents

class RsvpsController < BaseController

  before_filter :login_required, :only => [:new, :edit, :update, :destroy, :create]
  before_filter :find_event
  before_filter :require_ownership_or_moderator, :only => [:edit, :update, :destroy]

  def find_event
    @event = Event.find(params[:event_id])
  rescue
    redirect_to events_url
  end

  # GET /rsvps/new
  def new
    @rsvp = @event.rsvps.new
  end

  # GET /posts/1;edit
  def edit
  end

  # POST /rsvps
  # POST /rsvps.xml
  def create
    @rsvp = @event.rsvps.new(params[:rsvp])
    @rsvp.user = current_user
    respond_to do |format|
      if @rsvp.save
        flash[:notice] = :your_rsvp_was_successfully_created.l
        format.html { redirect_to [@event] }
        format.js
      else
        format.html { render :action => "new" }
        format.js        
      end
    end
  end
  
  # PUT /rsvps/1
  # PUT /rsvps/1.xml
  def update
    @rsvp.attendees_count = params[:rsvp][:attendees_count]
    respond_to do |format|
      if @rsvp.save
        flash[:notice] = :your_rsvp_was_successfully_updated.l
        format.html { redirect_to [@event] }
      else
        format.html { render :action => "edit" }  
      end
    end
  end
  
  # DELETE /rsvps/1
  # DELETE /rsvps/1.xml
  def destroy
    @rsvp.destroy
    respond_to do |format|
      format.html { 
        flash[:notice] = :your_rsvp_has_been_retracted.l
        redirect_to [@event]   
        }
    end
  end
 
  private
  
  def require_ownership_or_moderator
    @rsvp = @event.rsvps.find(params[:id])
    @user = @rsvp.user
    unless admin? || moderator? || (@rsvp && (@user.eql?(current_user)))
      redirect_to [@event] and return false
    end
  rescue
    redirect_to [@event]
  end
  
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
community_engine-2.3.2 app/controllers/rsvps_controller.rb
community_engine-2.3.1 app/controllers/rsvps_controller.rb
community_engine-2.3.0 app/controllers/rsvps_controller.rb
community_engine-2.1.0 app/controllers/rsvps_controller.rb
community_engine-2.0.0 app/controllers/rsvps_controller.rb
community_engine-2.0.0.beta3 app/controllers/rsvps_controller.rb
community_engine-2.0.0.beta2 app/controllers/rsvps_controller.rb
community_engine-2.0.0.beta1 app/controllers/rsvps_controller.rb