Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class AnnouncementsController < ApplicationController
- require 'nokogiri'
- require 'open-uri'
- before_action :set_announcement, only: [:show, :edit, :update, :destroy]
- # GET /announcements
- # GET /announcements.json
- def index
- @announcements = Announcement.all
- end
- # GET /announcements/1
- # GET /announcements/1.json
- def show
- end
- # GET /announcements/new
- def new
- @announcement = Announcement.new
- end
- # GET /announcements/1/edit
- def edit
- end
- # POST /announcements
- # POST /announcements.json
- def create
- @announcement = Announcement.new(announcement_params)
- respond_to do |format|
- if @announcement.save
- format.html { redirect_to @announcement, notice: 'Announcement was successfully created.' }
- format.json { render :show, status: :created, location: @announcement }
- else
- format.html { render :new }
- format.json { render json: @announcement.errors, status: :unprocessable_entity }
- end
- end
- end
- # PATCH/PUT /announcements/1
- # PATCH/PUT /announcements/1.json
- def update
- respond_to do |format|
- if @announcement.update(announcement_params)
- format.html { redirect_to @announcement, notice: 'Announcement was successfully updated.' }
- format.json { render :show, status: :ok, location: @announcement }
- else
- format.html { render :edit }
- format.json { render json: @announcement.errors, status: :unprocessable_entity }
- end
- end
- end
- # DELETE /announcements/1
- # DELETE /announcements/1.json
- def destroy
- @announcement.destroy
- respond_to do |format|
- format.html { redirect_to announcements_url, notice: 'Announcement was successfully destroyed.' }
- format.json { head :no_content }
- end
- end
- def profnews()
- #_profnews_param = params[:profnews_param].to_s
- #_url = "http://www.teilar.gr/person_xml.php?pid="+ _profnews_param + "&type=a"
- _url = "http://www.teilar.gr/person_xml.php?pid=savvas@teilar.gr&type=a"
- _doc = Nokogiri::XML(open(_url)).xpath('/root/*[starts-with(name(),"news_")]')
- _doc.each do |item|
- _temp_hash = Hash.new
- _temp_hash[:title] = item.css("title").text
- _temp_hash[:announcDate] = item.css("news_date").text
- _temp_hash[:desc] = item.css("descr").text
- _temp_hash[:attachment] = item.css("attachment").text
- @announcement = Announcement.new(:title =>_temp_hash[:title], :announcDate =>_temp_hash[:announcDate], :desc => _temp_hash[:desc], :attachment => _temp_hash[:attachment])
- @announcement.save
- end
- end
- private
- # Use callbacks to share common setup or constraints between actions.
- def set_announcement
- @announcement = Announcement.find(params[:id])
- end
- # Never trust parameters from the scary internet, only allow the white list through.
- def announcement_params
- params.require(:announcement).permit(:title, :announcDate, :desc, :attachment)
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement