From 8c80e560193aeaacb6570e25b41338f3af63d831 Mon Sep 17 00:00:00 2001 From: fanqiang <316257774@qq.com> Date: Sun, 4 Aug 2013 10:11:38 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E5=88=97=E8=A1=A8=E7=9A=84=E7=BB=93=E6=9E=84=EF=BC=8C=E6=B7=BB?= =?UTF-8?q?=E5=8A=A0=E4=BA=86=E5=88=86=E9=A1=B5=EF=BC=8C=E5=B9=B6=E4=B8=94?= =?UTF-8?q?=E4=BF=AE=E6=94=B9=E4=BA=86=E6=96=B0=E5=BB=BA=E9=9C=80=E6=B1=82?= =?UTF-8?q?=E7=9A=84BUG=EF=BC=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/bids_controller.rb | 27 +++++++++++----- app/models/bid.rb | 3 +- app/views/bids/_bid_show.html.erb | 49 ++++++++++++++++++++++++++++++ app/views/bids/_new_bid.html.erb | 2 +- app/views/bids/index.html.erb | 46 ++-------------------------- app/views/bids/new_bid.js.erb | 1 + 6 files changed, 76 insertions(+), 52 deletions(-) create mode 100644 app/views/bids/_bid_show.html.erb create mode 100644 app/views/bids/new_bid.js.erb diff --git a/app/controllers/bids_controller.rb b/app/controllers/bids_controller.rb index 846956106..dca354c6f 100644 --- a/app/controllers/bids_controller.rb +++ b/app/controllers/bids_controller.rb @@ -4,12 +4,12 @@ class BidsController < ApplicationController helper :watchers def index - if params[:bid_title] - Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description]) - end + # @requirement_title = "4" - @offset = 0 - @limit = 20 + @limit = 5 + @bid_count = Bid.count + @bid_pages = Paginator.new @bid_count, @limit, params['page'] + @offset ||= @bid_pages.offset @bids = Bid.offset(@offset).limit(@limit).all end @@ -96,7 +96,7 @@ class BidsController < ApplicationController # @message_count = a_message.count respond_to do |format| - format.html { redirect_to :back } + # format.html format.js #format.api { render_api_ok } end @@ -120,7 +120,20 @@ class BidsController < ApplicationController end def new_bid - + if params[:bid_title] + Bid.creat_bids(params[:bid_budget], params[:bid_deadline], params[:bid_title] , params[:bid_description]) + end + @limit = 5 + @bid_count = Bid.count + @bid_pages = Paginator.new @bid_count, @limit, params['page'] + @offset ||= @bid_pages.offset + @bids = Bid.offset(@offset).limit(@limit).all + respond_to do |format| + # format.html + format.html { redirect_to :back } + format.js + # format.api { render_api_ok } + end end def more diff --git a/app/models/bid.rb b/app/models/bid.rb index f7c599c94..b5a0028ce 100644 --- a/app/models/bid.rb +++ b/app/models/bid.rb @@ -12,7 +12,8 @@ class Bid < ActiveRecord::Base validates_length_of :name, :maximum => NAME_LENGTH_LIMIT validates_length_of :description, :maximum => DESCRIPTION_LENGTH_LIMIT - validates_presence_of :author_id, :name + validates_presence_of :author_id, :name, :deadline + # validates_format_of :deadline, :with => validate :validate_user acts_as_watchable diff --git a/app/views/bids/_bid_show.html.erb b/app/views/bids/_bid_show.html.erb new file mode 100644 index 000000000..42b5bc163 --- /dev/null +++ b/app/views/bids/_bid_show.html.erb @@ -0,0 +1,49 @@ + + + +
需求列表 +
+ <%= toggle_link l(:button_bidding), 'put-bid-form', {:focus => 'project_id'} %> +
+ +<% bids.each do |bid|%> + + + + + + +
<%= link_to image_tag(url_to_avatar(bid.author), :class => 'avatar'), :class => "avatar" %> + + + + + + + + + + + +
<%= link_to(bid.author, user_path(bid.author), :class => 'bid_user') %>:<%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %>
+ + + + + + + +
悬赏:¥<%= bid.budget%>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid)%>)应标(<%= link_to bid.commit, respond_path(bid)%>)反馈(<%= link_to bid.watcher_users.count, respond_path(bid)%>)关注
<%= format_time bid.created_at %>
+
+ + + + +
<%= bid.description%>
+
+<% end %> + \ No newline at end of file diff --git a/app/views/bids/_new_bid.html.erb b/app/views/bids/_new_bid.html.erb index 2ec149e19..897a26bd9 100644 --- a/app/views/bids/_new_bid.html.erb +++ b/app/views/bids/_new_bid.html.erb @@ -4,7 +4,7 @@ } <%= form_tag({:controller => 'bids', -:action => 'index', +:action => 'new_bid', :remote => true, :method => :post, :id => 'new-bid-form'}) do %> diff --git a/app/views/bids/index.html.erb b/app/views/bids/index.html.erb index 0ae6754e7..4d622b489 100644 --- a/app/views/bids/index.html.erb +++ b/app/views/bids/index.html.erb @@ -2,47 +2,7 @@ <%= render :partial => 'new_bid' %> - - - -
需求列表 -
- <%= toggle_link l(:button_bidding), 'put-bid-form', {:focus => 'project_id'} %> -
+
+ <%= render :partial => 'bid_show', :locals => {:bids => @bids, :bid_pages => @bid_pages} %> +
-<% @bids.each do |bid|%> - - - - - - -
<%= link_to image_tag(url_to_avatar(bid.author), :class => 'avatar'), :class => "avatar" %> - - - - - - - - - - - -
<%= link_to(bid.author, user_path(bid.author), :class => 'bid_user') %>:<%= link_to(bid.name, respond_path(bid), :class => 'bid_path') %>
- - - - - - - -
悬赏:¥<%= bid.budget%>(<%= link_to bid.biding_projects.count, project_for_bid_path(bid)%>)应标(<%= link_to bid.commit, respond_path(bid)%>)反馈(<%= link_to bid.watcher_users.count, respond_path(bid)%>)关注
<%= format_time bid.created_at %>
-
- - - - -
<%= bid.description%>
-
-<% end %> diff --git a/app/views/bids/new_bid.js.erb b/app/views/bids/new_bid.js.erb new file mode 100644 index 000000000..aa9547d3f --- /dev/null +++ b/app/views/bids/new_bid.js.erb @@ -0,0 +1 @@ +$('#bid-show').html('<%= escape_javascript(render(:partial => 'bids/bid_show', :locals => {:bids => @bids, :bid_pages => @bid_pages})) %>'); \ No newline at end of file