Class: SubscribersController

Inherits:
ApplicationController show all
Defined in:
lib/forge/app/controllers/subscribers_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#app_init

Instance Method Details

#createObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/forge/app/controllers/subscribers_controller.rb', line 6

def create
  @subscriber = Subscriber.new(params[:subscriber])

  respond_to do |format|
    if @subscriber.save
      format.html {
        flash[:notice] = 'You have been subscribed successfully.'
        redirect_to :action => "index"
      }
      format.xml  { render :xml => @subscriber, :status => :created }
    else
      format.html { render :action => "index" }
      format.xml  { render :xml => @subscriber.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/forge/app/controllers/subscribers_controller.rb', line 23

def destroy
  @subscriber = Subscriber.find_by_email(params[:email])
  if @subscriber
    @subscriber.destroy
    respond_to do |format|
      format.html {
        flash[:notice] = "You have been unsubscribed."
        redirect_to :action => "index"
      }
      format.xml  { head :ok }
    end
  else
    respond_to do |format|
      format.html {
        flash[:warning] = "Your email was not found.  Are you sure you are subscribed?"
        redirect_to :action => "index"
      }
      format.xml  { head :bad_request }
    end
  end
end

#indexObject



2
3
4
# File 'lib/forge/app/controllers/subscribers_controller.rb', line 2

def index
  @subscriber = Subscriber.new
end