Advertisement
Guest User

Untitled

a guest
Oct 5th, 2016
149
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.99 KB | None | 0 0
  1. class AnnouncementsController < ApplicationController
  2. require 'nokogiri'
  3. require 'open-uri'
  4.  
  5. before_action :set_announcement, only: [:show, :edit, :update, :destroy]
  6.  
  7. # GET /announcements
  8. # GET /announcements.json
  9. def index
  10. @announcements = Announcement.all
  11. end
  12.  
  13. # GET /announcements/1
  14. # GET /announcements/1.json
  15. def show
  16. end
  17.  
  18. # GET /announcements/new
  19. def new
  20. @announcement = Announcement.new
  21. end
  22.  
  23. # GET /announcements/1/edit
  24. def edit
  25. end
  26.  
  27. # POST /announcements
  28. # POST /announcements.json
  29. def create
  30. @announcement = Announcement.new(announcement_params)
  31.  
  32. respond_to do |format|
  33. if @announcement.save
  34. format.html { redirect_to @announcement, notice: 'Announcement was successfully created.' }
  35. format.json { render :show, status: :created, location: @announcement }
  36. else
  37. format.html { render :new }
  38. format.json { render json: @announcement.errors, status: :unprocessable_entity }
  39. end
  40. end
  41. end
  42.  
  43. # PATCH/PUT /announcements/1
  44. # PATCH/PUT /announcements/1.json
  45. def update
  46. respond_to do |format|
  47. if @announcement.update(announcement_params)
  48. format.html { redirect_to @announcement, notice: 'Announcement was successfully updated.' }
  49. format.json { render :show, status: :ok, location: @announcement }
  50. else
  51. format.html { render :edit }
  52. format.json { render json: @announcement.errors, status: :unprocessable_entity }
  53. end
  54. end
  55. end
  56.  
  57. # DELETE /announcements/1
  58. # DELETE /announcements/1.json
  59. def destroy
  60. @announcement.destroy
  61. respond_to do |format|
  62. format.html { redirect_to announcements_url, notice: 'Announcement was successfully destroyed.' }
  63. format.json { head :no_content }
  64. end
  65. end
  66.  
  67. def profnews()
  68. #_profnews_param = params[:profnews_param].to_s
  69. #_url = "http://www.teilar.gr/person_xml.php?pid="+ _profnews_param + "&type=a"
  70. _url = "http://www.teilar.gr/person_xml.php?pid=savvas@teilar.gr&type=a"
  71. _doc = Nokogiri::XML(open(_url)).xpath('/root/*[starts-with(name(),"news_")]')
  72. _doc.each do |item|
  73. _temp_hash = Hash.new
  74. _temp_hash[:title] = item.css("title").text
  75. _temp_hash[:announcDate] = item.css("news_date").text
  76. _temp_hash[:desc] = item.css("descr").text
  77. _temp_hash[:attachment] = item.css("attachment").text
  78. @announcement = Announcement.new(:title =>_temp_hash[:title], :announcDate =>_temp_hash[:announcDate], :desc => _temp_hash[:desc], :attachment => _temp_hash[:attachment])
  79. @announcement.save
  80. end
  81. end
  82.  
  83. private
  84. # Use callbacks to share common setup or constraints between actions.
  85. def set_announcement
  86. @announcement = Announcement.find(params[:id])
  87. end
  88.  
  89. # Never trust parameters from the scary internet, only allow the white list through.
  90. def announcement_params
  91. params.require(:announcement).permit(:title, :announcDate, :desc, :attachment)
  92. end
  93. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement