Class: EventsPassTypesController
- Inherits:
-
ArtfullyOseController
- Object
- ActionController::Base
- ArtfullyOseController
- EventsPassTypesController
- Defined in:
- app/controllers/events_pass_types_controller.rb
Instance Method Summary collapse
Instance Method Details
#create ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'app/controllers/events_pass_types_controller.rb', line 24 def create @events_pass_type = EventsPassType.new.tap do |ept| ept.organization = current_organization ept.event = @event ept.limit_per_pass = params[:events_pass_type][:limit_per_pass] ept.pass_type = current_organization.pass_types.find(params[:events_pass_type][:pass_type]) ept.ticket_types = Set.new(params[:events_pass_type][:ticket_types].reject!(&:blank?)) ept.excluded_shows = Set.new(params[:events_pass_type][:excluded_shows].reject!(&:blank?)) ept.active = params[:events_pass_type][:active] end if @events_pass_type.ticket_types.empty? flash[:error] = "Please select at least one Ticket Type for this pass." redirect_to new_event_events_pass_type_path(@event) and return end if @events_pass_type.save flash[:notice] = "Your pass has been attached to this event." else flash[:error] = @events_pass_type.errors..to_sentence end redirect_to event_events_pass_types_path(@event) end |
#edit ⇒ Object
48 49 50 |
# File 'app/controllers/events_pass_types_controller.rb', line 48 def edit @events_pass_type = EventsPassType.find(params[:id]) end |
#index ⇒ Object
5 6 7 8 9 10 11 12 13 |
# File 'app/controllers/events_pass_types_controller.rb', line 5 def index @no_pass_types = current_organization.pass_types.empty? @events_pass_types = @event.events_pass_types # if they've set up a pass type but this event doesn't have any pass types yet, then kick them right to /new if @events_pass_types.empty? && !@no_pass_types redirect_to new_event_events_pass_type_path(@event) and return end end |
#new ⇒ Object
15 16 17 18 19 20 21 22 |
# File 'app/controllers/events_pass_types_controller.rb', line 15 def new @events_pass_type = EventsPassType.new @pass_type_options = current_organization.pass_types .reject{|pt| @event.events_pass_types.collect(&:pass_type_id).include?(pt.id)} .collect{|pass_type| [pass_type.name, pass_type.id]}.sort{|a, b| a[0] <=> b[0]} @pass_types = current_organization.pass_types.empty? end |
#update ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'app/controllers/events_pass_types_controller.rb', line 52 def update @events_pass_type = EventsPassType.find(params[:id]) @events_pass_type.limit_per_pass = params[:events_pass_type][:limit_per_pass] @events_pass_type.ticket_types = Set.new(params[:events_pass_type][:ticket_types].reject!(&:blank?)) @events_pass_type.excluded_shows = Set.new(params[:events_pass_type][:excluded_shows].reject!(&:blank?)) @events_pass_type.active = params[:events_pass_type][:active] if @events_pass_type.ticket_types.empty? flash[:error] = "Please select at least one Ticket Type for this pass." redirect_to new_event_events_pass_type_path(@event) and return end if @events_pass_type.save flash[:notice] = "Your pass has been updated." else flash[:error] = @events_pass_type.errors..to_sentence end redirect_to event_events_pass_types_path(@event) end |