forked from huacnlee/quora
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:huacnlee/quora
- Loading branch information
Showing
25 changed files
with
321 additions
and
15 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
# coding: UTF-8 | ||
class Cpanel::CommentsController < CpanelController | ||
|
||
def index | ||
@comments = initialize_grid(Comment, | ||
:order => 'id', | ||
:order_direction => 'desc') | ||
|
||
respond_to do |format| | ||
format.html # index.html.erb | ||
format.json | ||
end | ||
end | ||
|
||
def show | ||
@comment = Comment.find(params[:id]) | ||
|
||
respond_to do |format| | ||
format.html # show.html.erb | ||
format.json | ||
end | ||
end | ||
|
||
def new | ||
@comment = Comment.new | ||
|
||
respond_to do |format| | ||
format.html # new.html.erb | ||
format.json | ||
end | ||
end | ||
|
||
def edit | ||
@comment = Comment.find(params[:id]) | ||
end | ||
|
||
def create | ||
@comment = Comment.new(params[:comment]) | ||
|
||
respond_to do |format| | ||
if @comment.save | ||
format.html { redirect_to(cpanel_comments_path, :notice => 'Comment 创建成功。') } | ||
format.json | ||
else | ||
format.html { render :action => "new" } | ||
format.json | ||
end | ||
end | ||
end | ||
|
||
def update | ||
@comment = Comment.find(params[:id]) | ||
|
||
respond_to do |format| | ||
if @comment.update_attributes(params[:comment]) | ||
format.html { redirect_to(cpanel_comments_path, :notice => 'Comment 更新成功。') } | ||
format.json | ||
else | ||
format.html { render :action => "edit" } | ||
format.json | ||
end | ||
end | ||
end | ||
|
||
def destroy | ||
@comment = Comment.find(params[:id]) | ||
@comment.destroy | ||
|
||
respond_to do |format| | ||
format.html { redirect_to(cpanel_comments_path,:notice => "删除成功。") } | ||
format.json | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
module Cpanel::CommentsHelper | ||
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,16 @@ | ||
# coding: utf-8 | ||
class BaseModel | ||
# 检测敏感词 | ||
def spam?(attr) | ||
value = eval("self.#{attr}") | ||
return false if value.blank? | ||
if value.class == [].class | ||
value = value.join(" ") | ||
end | ||
spam_reg = Regexp.new(Setting.spam_words) | ||
if matched = spam_reg.match(value) | ||
self.errors.add(attr,"带有敏感内容[#{matched.to_a.join(",")}],请注意一下!") | ||
return false | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
<%= content_for :base_sitemap do %> | ||
<a href="<%= cpanel_comments_path %>">cpanel_comments</a> » | ||
<% end %> | ||
<%= content_for :styles do %> | ||
<% end %> | ||
|
||
<%= spaceless do %> | ||
<div class="tools"> | ||
<a href="<%= cpanel_comments_path %>" class="button small left<%= ' checked' if params[:action] == "index" %>">查看所有</a> | ||
<% if ["edit","update"].index(params[:action]) %> | ||
<a href="#" class="button small checked">编辑</a> | ||
<% end %> | ||
<a href="<%= new_cpanel_comment_path %>" class="button small right<%= ' checked' if ["new","create"].index(params[:action]) %>">新建</a> | ||
</div> | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
<div id="cpanel_comment" class="form"> | ||
<%= simple_form_for(@comment, | ||
:url => (@comment.id.blank? ? cpanel_comments_path : cpanel_comment_path(@comment.id)) ) do |f| %> | ||
|
||
<div class="inputs"> | ||
<%= f.input :body %> | ||
<%= f.input :user_id %> | ||
<%= f.input :commentable_type %> | ||
<%= f.input :commentable_id %> | ||
</div> | ||
<div class="actions"> | ||
<button type="submit">提交</button> | ||
或者 <%= link_to '返回', cpanel_comments_path %> | ||
</div> | ||
<% end %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<%= content_for :sitemap do %> | ||
<span class="current">修改</span> | ||
<% end %> | ||
<%= render 'base' %> | ||
<%= render 'form' %> | ||
|
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,27 @@ | ||
<%= content_for :sitemap do %> | ||
<span class="current">列表</span> | ||
<% end %> | ||
<%= render 'base' %> | ||
|
||
<div id="cpanel_comments"> | ||
<%= grid(@comments, :show_filters => :false) do |g| | ||
g.column :column_name => 'body', :attribute_name => 'body' do |c| | ||
c.body if !c.body.blank? | ||
end | ||
g.column :column_name => 'user_id', :attribute_name => 'user_id' do |c| | ||
c.user_id if !c.user_id.blank? | ||
end | ||
g.column :column_name => 'commentable_type', :attribute_name => 'commentable_type' do |c| | ||
c.commentable_type if !c.commentable_type.blank? | ||
end | ||
g.column :column_name => 'commentable_type', :attribute_name => 'commentable_type' do |c| | ||
c.commentable_id if !c.commentable_id.blank? | ||
end | ||
g.column :column_name => '创建时间', :attribute_name => 'created_at', :td_html_attrs => { :style => "width:120px;" } | ||
g.column :td_html_attrs => { :style => "width:50px; text-align:right;" } do |c| | ||
raw "#{link_to image_tag("wice_grid/delete.png", :style => "margin-bottom:-4px"), cpanel_comment_path(c.id), :method => :delete, :confirm => '确定要删除吗?'}" | ||
end | ||
end %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
<%= content_for :sitemap do %> | ||
<span class="current">新建</span> | ||
<% end %> | ||
<%= render 'base' %> | ||
<%= render 'form' %> |
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 @@ | ||
<%= content_for :sitemap do %> | ||
<span class="current">查看</span> | ||
<% end %> | ||
<%= render 'base' %> | ||
<div class="tools"> | ||
<%= link_to '修改', edit_cpanel_comment_path(@comment) %> | | ||
<%= link_to '返回', cpanel_comments_path %> | ||
</div> | ||
<div id="cpanel_comment"> | ||
<p> | ||
<b>Body:</b> | ||
<%= @comment.body %> | ||
</p> | ||
<p> | ||
<b>User:</b> | ||
<%= @comment.user_id %> | ||
</p> | ||
<p> | ||
<b>Commentable type:</b> | ||
<%= @comment.commentable_type %> | ||
</p> | ||
<p> | ||
<b>Commentable:</b> | ||
<%= @comment.commentable_id %> | ||
</p> | ||
</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 |
---|---|---|
|
@@ -67,5 +67,6 @@ | |
resources :asks | ||
resources :answers | ||
resources :topics | ||
resources :comments | ||
end | ||
end |
Oops, something went wrong.