Class: InfosourcesController

Inherits:
ApplicationController
  • Object
show all
Includes:
InfosourcesHelper
Defined in:
app/controllers/infosources_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject

POST /infosources POST /infosources.xml



100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'app/controllers/infosources_controller.rb', line 100

def create
  @infosource = Infosource.new(params[:infosource])

  respond_to do |format|
    if @infosource.save
      flash[:notice] = t :infosource_creation_success_flash
      format.html { redirect_to(@infosource) }
      format.xml  { render :xml => @infosource, :status => :created, :location => @infosource }
    else
      format.html { render :action => "new" }
      format.xml  { render :xml => @infosource.errors, :status => :unprocessable_entity }
    end
  end
end

#destroyObject

DELETE /infosources/1 DELETE /infosources/1.xml



134
135
136
137
138
139
140
141
142
# File 'app/controllers/infosources_controller.rb', line 134

def destroy
  @infosource = Infosource.find(params[:id])
  @infosource.destroy

  respond_to do |format|
    format.html { redirect_to(infosources_url) }
    format.xml  { head :ok }
  end
end

#editObject

GET /infosources/1/edit



94
95
96
# File 'app/controllers/infosources_controller.rb', line 94

def edit
  @infosource = Infosource.find(params[:id])
end

#fetchObject

GET /infosource/fetch/1 GET /infosource/fetch/1.xml



62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'app/controllers/infosources_controller.rb', line 62

def fetch
  @infosource = Infosource.find(params[:id])

  respond_to do |format|
    #FIXME Should not wait for finishing the job, a worker process should start and
    #email sent when the process is finished
    items_fetched = @infosource.fetch_source
    if !items_fetched.nil? and (items_fetched > 0)
      flash[:notice] = t :infosource_fetched_flash, :item_fetched => items_fetched
      format.html { redirect_to :action => :show }
      format.xml  { render :xml => @infosource, :status => :fetched, :location => @infosource }
    else
      flash[:notice] = t :nothing_was_fetched_flash
      format.html { render :action => "show" }
      format.xml  { render :xml => @infosource.errors, :status => :unprocessable_entity }
    end
  end
  Sunspot.commit_if_dirty
end

#indexObject

GET /infosources GET /infosources.xml



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/controllers/infosources_controller.rb', line 14

def index
  @infosources = Infosource.all

=begin
  page = (params[:page] || 1).to_i
  #OPTIMIZE this should be optimized for mysel perhaps, I suspect too much of data is read here,
  #exploit limit in sql, index the necessary columns
  @articles = Article.paginate(:order => 'created_at DESC',
                               :page => page)
=end
  respond_to do |format|
    format.html # index.html.erb
    format.xml  { render :xml => @infosources }
  end
end

#newObject

GET /infosources/new GET /infosources/new.xml



84
85
86
87
88
89
90
91
# File 'app/controllers/infosources_controller.rb', line 84

def new
  @infosource = Infosource.new

  respond_to do |format|
    format.html # new.html.erb
    format.xml  { render :xml => @infosource }
  end
end

#showObject

GET /infosources/1 GET /infosources/1.xml



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'app/controllers/infosources_controller.rb', line 44

def show
  @infosource = Infosource.find(params[:id])

  #OPTIMIZE new articles for a specific Infosource selection
  #perhaps db indexing or query optimization would help
  #TODO the show for infosource should have different view than the one used from the article
  page = (params[:page] || 1).to_i
  @articles = Article.paginate_by_infosource_id(@infosource, :order => 'created_at DESC',
                                                :page => page)

  respond_to do |format|
    format.html # show.html.erb
    format.xml  { render :xml => @infosource }
  end
end

#testerObject

simple tester page for the content cutting algorithm



38
39
40
# File 'app/controllers/infosources_controller.rb', line 38

def tester
  @webpage_content = ContentScrapper.default.scrap_content(params[:url]) if params[:url]
end

#updateObject

PUT /infosources/1 PUT /infosources/1.xml



117
118
119
120
121
122
123
124
125
126
127
128
129
130
# File 'app/controllers/infosources_controller.rb', line 117

def update
  @infosource = Infosource.find(params[:id])

  respond_to do |format|
    if @infosource.update_attributes(params[:infosource])
      flash[:notice] = t :infosource_update_success_flash
      format.html { redirect_to(@infosource) }
      format.xml  { head :ok }
    else
      format.html { render :action => "edit" }
      format.xml  { render :xml => @infosource.errors, :status => :unprocessable_entity }
    end
  end
end