daily pastebin goal
70%
SHARE
TWEET

Untitled

a guest Jul 11th, 2018 53 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. def update
  2.     params[:advert][:resort_ids] ||= []     # Fix from one of Ryan's railscasts for checkbox updates
  3.  
  4.     if current_user.admin
  5.       @advert.cleared_for_release = params[:advert][:cleared_for_release]     # protected with attr_protected in model
  6.       @advert.front_page = params[:advert][:front_page]                       # protected with attr_protected in model
  7.       @advert.save
  8.     end
  9.    
  10.     puts "**** SUBMITTED resort count :" + params[:advert][:resort_ids].length.to_s
  11.     puts "**** ALLOWED resort count :" + current_user.max_allowed_resorts_per_advert.to_s
  12.    
  13.     allowed_resorts = current_user.max_allowed_resorts_per_advert
  14.     requested_resorts = params[:advert][:resort_ids].length
  15.    
  16.     if requested_resorts > allowed_resorts
  17.       flash[:notice] = "Sorry you're only allowed to list against #{allowed_resorts} resorts."
  18.       render :action => 'edit'              # Update probably failed validation, re edit
  19.     end
  20.  
  21.    
  22.     @advert = Advert.find(params[:id])
  23.     if @advert.update_attributes(params[:advert])
  24.       flash[:notice] = "Updated. Done."
  25.       redirect_to @advert
  26.     else
  27.       render :action => 'edit'              # Update probably failed validation, re edit
  28.     end
  29.   end
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top