Shriyansh_Agrawal

Untitled

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