Guest User

Untitled

a guest
May 23rd, 2018
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.46 KB | None | 0 0
  1. ##performance:edit
  2. def edit
  3. @presenter = Performance.find(params[:id]);
  4. @presenter[:venue_name] = @presenter.venue.name
  5. @presenter[:city] = @presenter.venue.location.city.capitalize
  6. @presenter[:state] = @presenter.venue.location.state
  7. @presenter[:countryUS] = @presenter.venue.location.state
  8. @presenter[:date] = @presenter.datetime
  9. @presenter[:time] = @presenter.datetime
  10. end
  11.  
  12.  
  13.  
  14. ##performance:create
  15. def create
  16.  
  17. @artist = Artist.find_by_id(@current_user.artist_id)
  18.  
  19. #Step 1 - See if this location exists already
  20. @location = Location.find_by_city_and_state(params[:presenter][:city].upcase, params[:presenter][:countryUS])
  21.  
  22. #If it doesn't, create a new one
  23. if @location.nil?
  24. @location = Location.new(:city=>params[:presenter][:city].upcase, :state => params[:presenter][:countryUS])
  25. @location.save
  26. end
  27.  
  28. #We've got an ID
  29. params[:presenter][:location_id] = @location.id
  30.  
  31. @venue = Venue.find_by_name_and_location_id(params[:presenter][:venue_name], params[:presenter][:location_id])
  32.  
  33. #Step 2 - If this we can not find this venue at this location...
  34. if @venue.nil?
  35. #Then check to see if we can find the venue at any location
  36. @venue = Venue.find_by_name(params[:presenter][:venue_name])
  37. #And if we can't find that, then make a venue
  38. if @venue.nil?
  39. @venue = Venue.new(:name => params[:presenter][:venue_name], :location_id => params[:presenter][:location_id])
  40. @venue.save
  41. end
  42. end
  43.  
  44. params[:presenter][:venue_id] = @venue.id
  45.  
  46. #Step 3 - Make a Performance
  47.  
  48. #Step 3a - Format the date
  49. flash[:notice] = params[:presenter][:'date(li)']
  50. params[:presenter][:datetime] = DateTime.new(params[:presenter][:'date(1i)'].to_i, params[:presenter][:'date(2i)'].to_i, params[:presenter][:'date(3i)'
  51. ].to_i, params[:presenter][:'time(4i)'].to_i, params[:presenter][:'time(5i)'].to_i)
  52. @performance = Performance.find_by_venue_id_and_datetime(params[:presenter][:venue_id], params[:presenter][:datetime])
  53. if @performance.nil?
  54. @performance = Performance.new(:venue_id => params[:presenter][:venue_id], :datetime => params[:presenter][:datetime], :user_id => @current_user.id)
  55. if @performance.save
  56. @performance.artists << @artist
  57. redirect_to :action => :index
  58. flash[:notice] = "Performances Successfully Added"
  59. else
  60. render :action => :new
  61. end
  62. end
  63. end
Add Comment
Please, Sign In to add comment