Skip to content

Commit db4f01d

Browse files
committed
Signed-off-by: akgitcom <aksoft@163.com>
1 parent 8bca303 commit db4f01d

File tree

7 files changed

+12790
-6
lines changed

7 files changed

+12790
-6
lines changed

Gemfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ gem 'jquery-rails'
3838
#gem 'ruby-debug19', :require => 'ruby-debug'
3939
gem 'will_paginate', '~> 3.0.0'
4040
gem 'devise'
41-
gem "cancan"
41+
gem 'cancan'
42+
gem 'nokogiri'

Gemfile.lock

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ GEM
6060
treetop (~> 1.4.8)
6161
mime-types (1.17.2)
6262
multi_json (1.0.4)
63+
nokogiri (1.5.5-x86-mingw32)
6364
orm_adapter (0.3.0)
6465
polyglot (0.3.3)
6566
rack (1.4.1)
@@ -118,6 +119,7 @@ DEPENDENCIES
118119
coffee-rails (~> 3.2.1)
119120
devise
120121
jquery-rails
122+
nokogiri
121123
rails (= 3.2.1)
122124
sass-rails (~> 3.2.3)
123125
sqlite3

app/controllers/posts_controller.rb

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
class PostsController < ApplicationController
22
#http_basic_authenticate_with :name => "root", :password => "root", :except => [:index, :show]
3-
before_filter :authenticate_user!, :except => [:show, :index, :tagsearch]
4-
load_and_authorize_resource :except => [:show, :index, :tagsearch]
3+
before_filter :authenticate_user!, :except => [:show, :index, :tagsearch, :iteye]
4+
load_and_authorize_resource :except => [:show, :index, :tagsearch, :iteye]
55
# GET /posts
66
# GET /posts.json
77
def index
@@ -15,6 +15,34 @@ def index
1515
end
1616
end
1717

18+
def iteye
19+
# Get a Nokogiri::HTML::Document for the page we’re interested in...
20+
require 'nokogiri'
21+
require 'open-uri'
22+
page = params['page']
23+
@sarr = []
24+
# for page in (1..100).to_a do
25+
url = 'http://www.sosoina.com/Search_lei'+page.to_s+'.html'
26+
@doc = Nokogiri::HTML(open(url), nil, "utf-8")
27+
@li = {}
28+
@doc.css('.sr li').each_with_index do |link,i|
29+
if i>5
30+
@li[i] = {:txt => link.content}
31+
end
32+
end
33+
@liarr = []
34+
@doc.css('.sr li').each do |link|
35+
@liarr << link.content
36+
end
37+
@liarr.each_with_index do |la,i|
38+
if i<6
39+
@liarr.shift
40+
end
41+
end
42+
@sarr << @liarr
43+
# end
44+
end
45+
1846
def wap
1947
render :content_type=>"text/vnd.wap.wml", :layout=>false
2048
end
@@ -106,7 +134,6 @@ def create
106134
@postreset = params[:post]
107135
@postreset["tags_attributes"] = @tag
108136
@post = Post.new(@postreset)
109-
#@post = Post.new(@postreset)
110137

111138
respond_to do |format|
112139
if @post.save

app/views/posts/iteye.html.erb

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
2+
<br>
3+
<%= @sarr.in_groups_of(6) %>

app/views/posts/new.html.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22

33
<%= render 'form' %>
44

5-
<%= link_to 'Back', posts_path %>
5+
<%= link_to 'Back', posts_path %>

config/routes.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33

44

55
devise_for :users
6-
match '/posts/tagsearch' => 'posts#tagsearch'
6+
match '/posts/iteye' => 'posts#iteye'
7+
match '/posts/tagsearch/params' => 'posts#tagsearch#params'
78
resources :posts
89

910
get "posts/index"

0 commit comments

Comments
 (0)