Merge branch 'szzh' of http://repository.trustie.net/xianbo/trustie2 into szzh
commit
003b088091
@ -0,0 +1,34 @@
|
||||
class DiscussDemosController < ApplicationController
|
||||
def index
|
||||
@discuss_demo_list = DiscussDemo.where("body is not null").order("created_at desc").page(params[:page] || 1).per(10)
|
||||
end
|
||||
|
||||
def new
|
||||
@discuss_demo = DiscussDemo.create
|
||||
@discuss_demo.save!
|
||||
@discuss_demo
|
||||
end
|
||||
|
||||
def create
|
||||
|
||||
end
|
||||
|
||||
def update
|
||||
@discuss_demo = DiscussDemo.find(params[:id])
|
||||
@discuss_demo.update_attributes(:title => params[:discuss_demo][:title],:body => params[:discuss_demo][:body])
|
||||
redirect_to :controller=> 'discuss_demos',:action => 'show',:id => params[:id]
|
||||
end
|
||||
|
||||
def delete
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
DiscussDemo.delete_all(["id = ?",params[:id]])
|
||||
redirect_to :controller=> 'discuss_demos',:action => 'index'
|
||||
end
|
||||
|
||||
def show
|
||||
@discuss_demo = DiscussDemo.find(params[:id])
|
||||
end
|
||||
end
|
@ -0,0 +1,2 @@
|
||||
module DiscussDemosHelper
|
||||
end
|
@ -0,0 +1,4 @@
|
||||
class DiscussDemo < ActiveRecord::Base
|
||||
attr_accessible :title, :body
|
||||
has_many_kindeditor_assets :attachments, :dependent => :destroy
|
||||
end
|
@ -0,0 +1,15 @@
|
||||
class Kindeditor::Asset < ActiveRecord::Base
|
||||
self.table_name = 'kindeditor_assets'
|
||||
mount_uploader :asset, Kindeditor::AssetUploader
|
||||
validates_presence_of :asset
|
||||
before_save :update_asset_attributes
|
||||
attr_accessible :asset
|
||||
|
||||
private
|
||||
def update_asset_attributes
|
||||
if asset.present? && asset_changed?
|
||||
self.file_size = asset.file.size
|
||||
self.file_type = asset.file.content_type
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class Kindeditor::File < Kindeditor::Asset
|
||||
mount_uploader :asset, Kindeditor::FileUploader
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class Kindeditor::Flash < Kindeditor::Asset
|
||||
mount_uploader :asset, Kindeditor::FlashUploader
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class Kindeditor::Image < Kindeditor::Asset
|
||||
mount_uploader :asset, Kindeditor::ImageUploader
|
||||
end
|
@ -0,0 +1,3 @@
|
||||
class Kindeditor::Media < Kindeditor::Asset
|
||||
mount_uploader :asset, Kindeditor::MediaUploader
|
||||
end
|
@ -0,0 +1,25 @@
|
||||
<h1 style="">文章列表</h1>
|
||||
<div>
|
||||
<table border="1px solid !important" >
|
||||
<% @discuss_demo_list.each do |e| %>
|
||||
|
||||
<tr align="left" height="20">
|
||||
<td width="30%" ><%= truncate(e.title,:length => 50) %></td>
|
||||
<td align="center" width="60%">
|
||||
<%= truncate(e.body,:length => 50) %>
|
||||
</td>
|
||||
<td style=" margin-right: 1" width="10%">
|
||||
<%= link_to '查看文章',{:controller => 'discuss_demos',:action => 'show',:id=>e.id} %>
|
||||
</td>
|
||||
<td>
|
||||
|
||||
<%= link_to '删除文章',discuss_demo_path(e.id), :method => :delete,:confirm => l(:text_are_you_sure) %>
|
||||
</td>
|
||||
</tr>
|
||||
<tr height="20"></tr>
|
||||
<tr height="20"></tr>
|
||||
<% end %>
|
||||
</table>
|
||||
<% paginate @discuss_demo_list %>
|
||||
<%= link_to '新建文章',new_discuss_demo_path %>
|
||||
</div>
|
@ -0,0 +1,7 @@
|
||||
<%= javascript_include_tag src='/assets/kindeditor/kindeditor' %>
|
||||
<h1>新建文章</h1>
|
||||
<%= form_for @discuss_demo,:url => {:controller => 'discuss_demos',:action => "show",:id =>@discuss_demo.id, :method => :put} do |f| %>
|
||||
<%= f.text_field :title %>
|
||||
<%= f.kindeditor :body ,:owner_id => @discuss_demo.id%>
|
||||
<%= f.submit :value=> '提交' %>
|
||||
<% end %>
|
@ -0,0 +1,3 @@
|
||||
<h1><%= @discuss_demo.title %></h1>
|
||||
<%= textAreailizable @discuss_demo.body %>
|
||||
<%=link_to "返回首页",discuss_demos_path %>
|
@ -0,0 +1,19 @@
|
||||
RailsKindeditor.setup do |config|
|
||||
|
||||
# Specify the subfolders in public directory.
|
||||
# You can customize it , eg: config.upload_dir = 'this/is/my/folder'
|
||||
config.upload_dir = 'files/uploads'
|
||||
|
||||
# Allowed file types for upload.
|
||||
config.upload_image_ext = %w[gif jpg jpeg png bmp]
|
||||
config.upload_flash_ext = %w[swf flv]
|
||||
config.upload_media_ext = %w[swf flv mp3 wav wma wmv mid avi mpg asf rm rmvb]
|
||||
config.upload_file_ext = %w[doc docx xls xlsx ppt htm html txt zip rar gz bz2]
|
||||
|
||||
# Porcess upload image size
|
||||
# eg: 1600x1600 => 800x800
|
||||
# 1600x800 => 800x400
|
||||
# 400x400 => 400x400 # No Change
|
||||
# config.image_resize_to_limit = [800, 800]
|
||||
|
||||
end
|
@ -0,0 +1,9 @@
|
||||
class CreateDiscussDemos < ActiveRecord::Migration
|
||||
def change
|
||||
create_table :discuss_demos do |t|
|
||||
t.string :title
|
||||
t.text :body
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,17 @@
|
||||
class CreateKindeditorAssets < ActiveRecord::Migration
|
||||
def self.up
|
||||
create_table :kindeditor_assets do |t|
|
||||
t.string :asset
|
||||
t.integer :file_size
|
||||
t.string :file_type
|
||||
t.integer :owner_id
|
||||
t.string :asset_type # list by kindeditor: image, file, media, flash
|
||||
t.timestamps
|
||||
end
|
||||
end
|
||||
|
||||
def self.down
|
||||
drop_table :kindeditor_assets
|
||||
end
|
||||
end
|
||||
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in new issue