From 6fdb037b6ba6cf6024ff8abdabaa5ebd2fa33254 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Tue, 8 Apr 2014 09:02:12 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BC=80=E6=BA=90=E9=A1=B9=E7=9B=AE=E5=9F=BA?= =?UTF-8?q?=E6=9C=AC=E6=A1=86=E6=9E=B6=E5=AE=8C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../open_source_projects_controller.rb | 6 ++- app/models/open_source_project.rb | 48 +++++++++++++++++++ app/views/layouts/base_opensource_p.html.erb | 2 +- .../open_source_projects/_os_project.html.erb | 2 +- .../_show_topics.html.erb | 3 +- app/views/open_source_projects/index.html.erb | 8 ++-- 6 files changed, 60 insertions(+), 9 deletions(-) diff --git a/app/controllers/open_source_projects_controller.rb b/app/controllers/open_source_projects_controller.rb index 2c1e1e049..a77ac858e 100644 --- a/app/controllers/open_source_projects_controller.rb +++ b/app/controllers/open_source_projects_controller.rb @@ -17,12 +17,14 @@ class OpenSourceProjectsController < ApplicationController @created_at = params[:created_at] per_page_option = 10 - @open_source_projects = OpenSourceProject.all + @open_source_projects = OpenSourceProject.filter(@app_dir, @language, @created_at) @os_project_count = @open_source_projects.count @os_project_pages = Paginator.new @os_project_count, per_page_option, params['page'] + + @open_source_projects = @open_source_projects.offset(@os_project_pages.offset).limit(@os_project_pages.per_page) - @open_source_projects = OpenSourceProject.all + # @open_source_projects = OpenSourceProject.all respond_to do |format| format.html # index.html.erb diff --git a/app/models/open_source_project.rb b/app/models/open_source_project.rb index ca2d0be18..114a95cc4 100644 --- a/app/models/open_source_project.rb +++ b/app/models/open_source_project.rb @@ -19,6 +19,54 @@ class OpenSourceProject < ActiveRecord::Base { :include => :apply_project_master, :conditions => ["#{ApplyProjectMaster.table_name}.user_id = ?", user_id] } } + + def filter(app_dir, language, created_at) + filter_app_dir(app_dir).filter_language(language).filter_time(created_at) + end + + def self.filter(app_dir, language, created_at) + self.filter_app_dir(app_dir).filter_language(language).filter_time(created_at) + end + + scope :filter_app_dir, lambda {|args| + nil + } + + scope :filter_language, lambda {|*arg| + if arg[0].nil? + where(nil) + else + tagged_with(arg).order('updated_at desc') + end + } + + scope :filter_time, lambda {|args| + nil + } + + # def filter_app_dir(app_dir) + # nil + # end +# + # def self.filter_app_dir(app_dir) + # nil + # end +# + # def filter_language(language) + # nil + # end +# + # def self.filter_language(language) + # nil + # end +# + # def filter_time(created_at) + # nil + # end +# + # def self.filter_time(created_at) + # nil + # end def short_description(length = 255) diff --git a/app/views/layouts/base_opensource_p.html.erb b/app/views/layouts/base_opensource_p.html.erb index 3f64996c7..ce3fc9470 100644 --- a/app/views/layouts/base_opensource_p.html.erb +++ b/app/views/layouts/base_opensource_p.html.erb @@ -47,7 +47,7 @@ <% @open_source_project = OpenSourceProject.find(params[:id])%>
<%= image_tag(url_to_avatar(Project.find(2)), :class => 'avatar2') %> | +<%= image_tag('../images/avatars/Project/0', :class => 'avatar2') %> |
<%= @open_source_project.name %>
diff --git a/app/views/open_source_projects/_os_project.html.erb b/app/views/open_source_projects/_os_project.html.erb
index c609110de..e484ad714 100644
--- a/app/views/open_source_projects/_os_project.html.erb
+++ b/app/views/open_source_projects/_os_project.html.erb
@@ -1,6 +1,6 @@
- 图片
+ <%= image_tag('../images/avatars/Project/0', :class => 'avatar2') %>
diff --git a/app/views/open_source_projects/_show_topics.html.erb b/app/views/open_source_projects/_show_topics.html.erb index f4400ed39..9cb6c46af 100644 --- a/app/views/open_source_projects/_show_topics.html.erb +++ b/app/views/open_source_projects/_show_topics.html.erb @@ -8,7 +8,8 @@ <% memos.each do |topic| %>
|