Shriyansh_Agrawal

VenueCommercialsControlle

Apr 8th, 2016
33
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.71 KB | None | 0 0
  1. module Admin
  2. class VenueCommercialsController < Admin::BaseController
  3. load_and_authorize_resource :conference, find_by: :short_title
  4. load_and_authorize_resource :venue, through: :conference, singleton: true
  5. load_and_authorize_resource :commercial, through: :venue, singleton: true
  6.  
  7. def create
  8. @commercial = @venue.build_commercial(commercial_params)
  9. authorize! :create, @commercial
  10.  
  11. if @commercial.save
  12. redirect_to edit_admin_conference_venue_path,
  13. notice: 'Commercial was successfully created.'
  14. else
  15. redirect_to edit_admin_conference_venue_path,
  16. error: 'An error prohibited this Commercial from being saved: '\
  17. "#{@commercial.errors.full_messages.join('. ')}."
  18.  
  19. end
  20. end
  21.  
  22. def update
  23. if @commercial.update(commercial_params)
  24. redirect_to edit_admin_conference_venue_path,
  25. notice: 'Commercial was successfully updated.'
  26. else
  27. redirect_to edit_admin_conference_venue_path,
  28. error: 'An error prohibited this Commercial from being saved: '\
  29. "#{@commercial.errors.full_messages.join('. ')}."
  30. end
  31. end
  32.  
  33. def destroy
  34. @commercial.destroy
  35. redirect_to edit_admin_conference_venue_path, notice: 'Commercial was successfully destroyed.'
  36. end
  37.  
  38. def render_commercial
  39. result = Commercial.render_from_url(params[:url])
  40. if result[:error]
  41. render text: result[:error], status: 400
  42. else
  43. render text: result[:html]
  44. end
  45. end
  46.  
  47. private
  48.  
  49. def commercial_params
  50. params.require(:commercial).permit(:url)
  51. end
  52.  
  53. end
  54. end
Add Comment
Please, Sign In to add comment