Permalink
Browse files

Associated screen with new subscription object to make CanCan work fo…

…r subscriptions#manage
  • Loading branch information...
1 parent 45fe912 commit 79507bf861d2e25882ad9dbaab16452643fa010a @augustf augustf committed Dec 18, 2012
Showing with 9 additions and 5 deletions.
  1. +9 −5 app/controllers/subscriptions_controller.rb
@@ -23,10 +23,14 @@ def index
# GET /screen/:screen_id/subscriptions/manage
def manage
+ @subscription = Subscription.new
+ #stub out the screen ID so that CanCan can find an owner to auth
+ @subscription.screen_id = @screen.id
+ auth!
+
@this_field = Field.find(params[:field_id])
@fields = @screen.template.positions.collect{|p| p.field}
- @subscription = Subscription.new
-
+
respond_to do |format|
format.html # manage.html.erb
end
@@ -124,6 +128,9 @@ def save_all
@weights = params[:subscription_weight].values
end
+ #Do some fun auth stuff before we actually do anything dangerous
+ auth!
+
#Get a hold of all the subscriptions ID's that aren't in the form and destroy them (as the user deleted them in the form)
@all_screen_subs = @screen.subscriptions.where(:field_id => @field.id).map(&:id)
#Use the subtraction operator to get the difference between the arrays
@@ -152,9 +159,6 @@ def save_all
@this_subscription = Subscription.new
end
- #Do some fun auth stuff before we actually do anything dangerous
- auth!
-
#Update attributes of all subscriptions present in form and populate array with any errors encountered
@errnos[i] = !@this_subscription.update_attributes(:screen => @screen, :field => @field, :feed_id => feed_id, :weight => @weights[i])
end

0 comments on commit 79507bf

Please sign in to comment.