GeoRSS aggregator and Layar augmented reality server
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

subscriptions_controller.rb 2.4 KiB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  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. # GET /subscriptions/1/edit
  33. def edit
  34. @subscription = Subscription.find(params[:id])
  35. end
  36. # PUT /subscriptions/1
  37. # PUT /subscriptions/1.json
  38. def update
  39. @subscription = Subscription.find(params[:id])
  40. respond_to do |format|
  41. if @subscription.update_attributes(params[:subscription])
  42. format.html { redirect_to @subscription.layer, notice: 'Subscription updated OK' }
  43. format.json { head :no_content }
  44. else
  45. format.html { render action: "edit" }
  46. format.json { render json: @subscription.errors, status: :unprocessable_entity }
  47. end
  48. end
  49. end
  50. def destroy
  51. @subscription = Subscription.find(params[:id])
  52. @layer = @subscription.layer
  53. @subscription.destroy
  54. respond_to do |format|
  55. format.html { redirect_to @layer, notice: 'Subscription deleted OK' }
  56. format.json { head :no_content }
  57. end
  58. end
  59. end