Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ##performance:edit
- def edit
- @presenter = Performance.find(params[:id]);
- @presenter[:venue_name] = @presenter.venue.name
- @presenter[:city] = @presenter.venue.location.city.capitalize
- @presenter[:state] = @presenter.venue.location.state
- @presenter[:countryUS] = @presenter.venue.location.state
- @presenter[:date] = @presenter.datetime
- @presenter[:time] = @presenter.datetime
- end
- ##performance:create
- def create
- @artist = Artist.find_by_id(@current_user.artist_id)
- #Step 1 - See if this location exists already
- @location = Location.find_by_city_and_state(params[:presenter][:city].upcase, params[:presenter][:countryUS])
- #If it doesn't, create a new one
- if @location.nil?
- @location = Location.new(:city=>params[:presenter][:city].upcase, :state => params[:presenter][:countryUS])
- @location.save
- end
- #We've got an ID
- params[:presenter][:location_id] = @location.id
- @venue = Venue.find_by_name_and_location_id(params[:presenter][:venue_name], params[:presenter][:location_id])
- #Step 2 - If this we can not find this venue at this location...
- if @venue.nil?
- #Then check to see if we can find the venue at any location
- @venue = Venue.find_by_name(params[:presenter][:venue_name])
- #And if we can't find that, then make a venue
- if @venue.nil?
- @venue = Venue.new(:name => params[:presenter][:venue_name], :location_id => params[:presenter][:location_id])
- @venue.save
- end
- end
- params[:presenter][:venue_id] = @venue.id
- #Step 3 - Make a Performance
- #Step 3a - Format the date
- flash[:notice] = params[:presenter][:'date(li)']
- params[:presenter][:datetime] = DateTime.new(params[:presenter][:'date(1i)'].to_i, params[:presenter][:'date(2i)'].to_i, params[:presenter][:'date(3i)'
- ].to_i, params[:presenter][:'time(4i)'].to_i, params[:presenter][:'time(5i)'].to_i)
- @performance = Performance.find_by_venue_id_and_datetime(params[:presenter][:venue_id], params[:presenter][:datetime])
- if @performance.nil?
- @performance = Performance.new(:venue_id => params[:presenter][:venue_id], :datetime => params[:presenter][:datetime], :user_id => @current_user.id)
- if @performance.save
- @performance.artists << @artist
- redirect_to :action => :index
- flash[:notice] = "Performances Successfully Added"
- else
- render :action => :new
- end
- end
- end
Add Comment
Please, Sign In to add comment