forked from rubytaiwan/ruby-taiwan
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Topic/Reply can edit now; Replace time_ago_in_words as jquery.timeago;
- Loading branch information
Showing
20 changed files
with
273 additions
and
64 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# coding: utf-8 | ||
class RepliesController < ApplicationController | ||
before_filter :require_user | ||
|
||
def edit | ||
@reply = current_user.replies.find(params[:id]) | ||
end | ||
|
||
def update | ||
@reply = current_user.replies.find(params[:id]) | ||
|
||
if @reply.update_attributes(params[:reply]) | ||
redirect_to(topic_path(@reply.topic_id), :notice => '回帖删除成功.') | ||
else | ||
render :action => "edit" | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# coding: utf-8 | ||
# 软删除 | ||
module Mongoid | ||
module SoftDelete | ||
extend ActiveSupport::Concern | ||
|
||
def self.included(base) | ||
base.instance_eval do | ||
field :deleted_at, :type => DateTime | ||
|
||
default_scope where(:deleted_at => nil) | ||
alias_method :destroy!, :destroy | ||
|
||
include InstanceMethods | ||
end | ||
end | ||
|
||
module InstanceMethods | ||
def destroy | ||
if persisted? | ||
self.update_attributes(:deleted_at => Time.now.utc) | ||
end | ||
|
||
@destroyed = true | ||
freeze | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
<%= render '/topics/base' %> | ||
<% content_for :sitemap do %> | ||
<span class="current">修改回帖</span> | ||
<% end %> | ||
|
||
<div class="leftbox"> | ||
<div class="box"> | ||
<h1>修改回帖</h1> | ||
<%= form_for(@reply) do |f| %> | ||
<%= render "shared/error_messages", :target => @reply %> | ||
<div class="field"> | ||
<%= f.label :body %><br /> | ||
<%= f.text_area :body, :class => "topic_body_text_area long", :style => "height:400px" %> | ||
</div> | ||
<div class="actions"> | ||
<button class="button submit">保存</button> | ||
</div> | ||
<% end %> | ||
</div> | ||
</div> | ||
<div class="sidebar"> | ||
<div class="box"> | ||
回帖所在文章:<br /> | ||
<a href="<%= topic_path(@reply.topic_id) %>"><%= @reply.topic.title %></a> | ||
</div> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -20,6 +20,7 @@ | |
get :feed | ||
end | ||
end | ||
resources :replies | ||
resources :photos do | ||
collection do | ||
get :tiny_new | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,3 @@ | ||
// Like Rails DataHelper | ||
var DateHelper = { | ||
timeAgoInWords: function(from) { | ||
return this.distanceOfTimeInWords(new Date().getTime(), from); | ||
}, | ||
|
||
distanceOfTimeInWords: function(to, from) { | ||
seconds_ago = ((to - from) / 1000); | ||
minutes_ago = Math.floor(seconds_ago / 60) | ||
|
||
if(minutes_ago == 0) { return "不到一分钟";} | ||
if(minutes_ago == 1) { return "一分钟";} | ||
if(minutes_ago < 45) { return minutes_ago + "分钟";} | ||
if(minutes_ago < 90) { return "大约一小时";} | ||
hours_ago = Math.round(minutes_ago / 60); | ||
if(minutes_ago < 1440) { return hours_ago + "小时";} | ||
if(minutes_ago < 2880) { return "一天";} | ||
days_ago = Math.round(minutes_ago / 1440); | ||
if(minutes_ago < 43200) { return days_ago + "天";} | ||
if(minutes_ago < 86400) { return "大约一月";} | ||
months_ago = Math.round(minutes_ago / 43200); | ||
if(minutes_ago < 525960) { return months_ago + "月";} | ||
if(minutes_ago < 1051920) { return "大约一年";} | ||
years_ago = Math.round(minutes_ago / 525960); | ||
return "超过" + years_ago + "年" | ||
} | ||
} | ||
$(document).ready(function() { | ||
$("abbr.timeago").timeago(); | ||
}); |
Oops, something went wrong.