Class: SubscriptionsController

Inherits:
ApplicationController show all
Defined in:
app/controllers/subscriptions_controller.rb

Instance Method Summary (collapse)

Methods inherited from ApplicationController

#after_sign_in_path_for, #allow_cors, #allow_screen_if_unsecured, #apply_relative_root, #auth!, #check_for_initial_install, #compute_pending_moderation, #current_ability, #current_accessor, #current_screen, #extract_pagination_from_relation, #http_basic_user_name_and_password, #precompile_error_catch, #process_notification, #reapply_pagination, #restart_webserver, #screen_api, #set_locale, #set_time_zone, #set_version, #sign_in_screen, #sign_out_screen, #switch_to_main_app_ability, #switch_to_plugin_ability, #use_plugin_ability, #webserver_supports_restart?

Instance Method Details

- (Object) create

POST /screens/:screen_id/fields/:field_id/subscriptions POST /screens/:screen_id/fields/:field_id/subscriptions.xml



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'app/controllers/subscriptions_controller.rb', line 58

def create
  @subscription = Subscription.new(subscription_params)
  @subscription.screen = @screen
  @subscription.field = @field
  auth!

  # Verify the screen can read the feed
  ability = Ability.new(@screen)
  @subscription.feed = nil if ability.cannot?(:read, @subscription.feed)

  respond_to do |format|
    if @subscription.save
      format.html { redirect_to(screen_field_subscriptions_path(@screen, @field), :notice => t(:subscription_created)) }
      format.xml  { render :xml => @subscription, :status => :created, :location => @subscription }
      format.js
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @subscription.errors, :status => :unprocessable_entity }
      format.js
    end
  end
end

- (Object) destroy

DELETE /screens/:screen_id/fields/:field_id/subscriptions/1 DELETE /screens/:screen_id/fields/:field_id/subscriptions/1.xml



99
100
101
102
103
104
105
106
107
108
109
# File 'app/controllers/subscriptions_controller.rb', line 99

def destroy
  @subscription = Subscription.find(params[:id])
  auth!
  @subscription.destroy

  respond_to do |format|
    format.html { redirect_to(screen_field_subscription_path(@screen, @field)) }
    format.xml  { head :ok }
    format.js { head :ok }
  end
end

- (Object) edit

GET /screens/:screen_id/fields/:field_id/subscriptions/1/edit



51
52
53
54
# File 'app/controllers/subscriptions_controller.rb', line 51

def edit
  @subscription = Subscription.find(params[:id])
  auth!
end

- (Object) get_field



8
9
10
# File 'app/controllers/subscriptions_controller.rb', line 8

def get_field
  @field = Field.find(params[:field_id])
end

- (Object) get_screen



4
5
6
# File 'app/controllers/subscriptions_controller.rb', line 4

def get_screen
  @screen = Screen.find(params[:screen_id])
end

- (Object) index

GET /screens/:screen_id/fields/:field_id/subscriptions GET /screens/:screen_id/fields/:field_id/subscriptions.xml



14
15
16
17
18
19
20
21
# File 'app/controllers/subscriptions_controller.rb', line 14

def index
  @subscriptions = @screen.subscriptions.where(:field_id => @field.id)

  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @subscriptions }
  end
end

- (Object) new

GET /screens/:screen_id/fields/:field_id/subscriptions/new GET /screens/:screen_id/fields/:field_id/subscriptions/new.js



37
38
39
40
41
42
43
44
45
46
47
48
# File 'app/controllers/subscriptions_controller.rb', line 37

def new
  if params[:feed_id]
    @feed = Feed.find(params[:feed_id])
  else
    @subscriptions = @screen.subscriptions.where(:field_id => @field.id)
  end

  respond_to do |format|
    format.html # show.html.erb
    format.js
  end
end

- (Object) show

GET /screens/:screen_id/fields/:field_id/subscriptions/1 GET /screens/:screen_id/fields/:field_id/subscriptions/1.xml



25
26
27
28
29
30
31
32
33
# File 'app/controllers/subscriptions_controller.rb', line 25

def show
  @subscription = Subscription.find(params[:id])
  auth!

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @subscription }
  end
end

- (Object) update



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'app/controllers/subscriptions_controller.rb', line 81

def update
  @subscription = Subscription.find(params[:id])
  auth!

  respond_to do |format|
    if @subscription.update_attributes(subscription_params)
      format.html { redirect_to(screen_field_subscriptions_path(@screen, @field), :notice => t('subscriptions.records_updated')) }
      format.xml  { head :ok }
      format.js { head :ok }
    else
      format.html { redirect_to(screen_field_subscriptions_path(@screen, @field)) }
      format.xml  { render :xml => @subscription.errors, :status => :unprocessable_entity }
    end
  end
end