GeoRSS aggregator and Layar augmented reality server
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 
 
 

47 строки
1.8 KiB

  1. class SubscriptionsController < ApplicationController
  2. def create
  3. Rails.logger.debug "Feed URL: %s" % params['subscription']['feed_url']
  4. if Feed.where(:feed_url => params['subscription']['feed_url']).size == 1 # ensure this test returns the values we expect
  5. Rails.logger.debug "Adding existing feed to a new layer"
  6. @feed = Feed.where(:feed_url => params['subscription']['feed_url']).first
  7. @layer = Layer.find(params['subscription']['layer_id']) # assumes that the specified layer exists
  8. # Attach the existing feed to the specified layer (making sure we only add each one once)
  9. # @feed.layers << @layer unless @feed.layers.include?(@layer)
  10. else
  11. # Create a new feed
  12. Rails.logger.debug "Creating a new feed"
  13. @feed = Feed.create(:feed_url => params[:subscription][:feed_url])
  14. @layer = Layer.find(params['subscription']['layer_id']) # assumes that the specified layer exists
  15. # @feed.layers << @layer unless @feed.layers.include?(@layer)
  16. end
  17. @subscription = Subscription.new(:feed => @feed, :layer => @layer)
  18. begin
  19. respond_to do |format|
  20. if @subscription.save
  21. format.html { redirect_to @layer, notice: 'Feed added OK' }
  22. format.json { render json: @feed, status: :created, location: @feed }
  23. else
  24. format.html { render action: "new" }
  25. format.json { render json: @feed.errors, status: :unprocessable_entity }
  26. end
  27. end
  28. rescue ActiveRecord::RecordNotUnique
  29. redirect_to @layer, alert: 'That feed is already on this layer'
  30. end
  31. end
  32. def destroy
  33. @subscription = Subscription.find(params[:id])
  34. @layer = @subscription.layer
  35. @subscription.destroy
  36. respond_to do |format|
  37. format.html { redirect_to @layer, notice: 'Subscription deleted OK' }
  38. format.json { head :no_content }
  39. end
  40. end
  41. end