Skip to content

Instantly share code, notes, and snippets.

@morgler
Created May 22, 2014 14:18
Show Gist options
  • Save morgler/d4d9b608715c57ff72a0 to your computer and use it in GitHub Desktop.
Save morgler/d4d9b608715c57ff72a0 to your computer and use it in GitHub Desktop.
params permit
#encoding: UTF-8
class GigsController < InheritedResources::Base
include Icalendar
load_and_authorize_resource
before_filter :ensure_current_band, except: :feed
skip_before_filter :authenticate_user!, :only => :feed
skip_authorize_resource :only => :feed
def new
if (prototype_id = params[:prototype])
@gig = Gig.find(prototype_id).deep_dup
else
@gig = Gig.new(band: current_band, fee: 0)
@gig.attendances.build(user: current_user, state: 'scheduled') if current_user.member_of?(@gig.band)
end
end
def create
puts permitted_params.inspect
create!(notice: "Du hast einen neuen Gig für den #{I18n.l resource.date} in #{resource.city} angelegt.")
end
def index
@timerange = params[:timerange] || "future"
@gigs = case @timerange
when 'past' then
current_band.gigs.past
when 'future' then
current_band.gigs.future
else
current_band.gigs.by_date_asc
end
end
def view_monthly_summary
@date = params[:date] ? Date.parse(params[:date]) : Date.today
@gigs = current_band.gigs.fix.where('date >= ? AND date <= ?', @date.beginning_of_month, @date.end_of_month).by_date_asc
end
def destroy
destroy!(notice: 'Gig wurde gelöscht')
end
def destroy_multiple
params[:gig_ids].each do |gid|
current_band.gigs.destroy(gid)
end
redirect_to action: :index
end
def request_kilometers
gig = Gig.find(params[:id])
users = gig.request_kilometers
flash[:notice] = if users.empty?
"Es wurde keine SMS verschickt"
else
"SMS für KM-Anfrage wurde an #{users.map(&:name).to_sentence} versendet"
end
redirect_to :back
end
def feed
unless User.exists?(email: params[:email])
flash[:alert] = "Für die Emailadresse \"#{params[:email]}\" existiert leider kein iCalendar Feed."
redirect_to root_path and return
end
user = User.where(email: params[:email]).first
respond_to do |format|
format.ics {render :text => user.ical_feed(self)}
end
end
private
def build_date_time(date, time)
if time
datetime_utc = Time.zone.parse("#{date.to_s} #{time.hour}:#{time.min}").utc
datetime_utc.strftime("%Y%m%dT%H%M%SZ")
else
date
end
end
def permitted_params
params.permit(:gig => [:location,
:city,
:date,
:time_arrival, :time_soundcheck, :time_doors_open, :time_gig_start, :time_gig_end,
:state,
:fee_expected,
:fee,
:attendances_attributes, :attendance_ids,
:user_ids,
:band, :band_id,
:itinerary, :retained_itinerary,
:setlist, :retained_setlist] )
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment