From 5c4a62dcc4841770a505684ae4ca74e6c65038d0 Mon Sep 17 00:00:00 2001 From: lizanle <491823689@qq.com> Date: Mon, 16 Mar 2015 15:29:13 +0800 Subject: [PATCH] =?UTF-8?q?DiscussDemo=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/discuss_demo_controller.rb | 27 ++++++++++++++++++++++ app/helpers/discuss_demo_helper.rb | 2 ++ app/models/discuss_demo.rb | 4 ++++ app/views/discuss_demo/index.html.erb | 21 +++++++++++++++++ app/views/discuss_demo/new.html.erb | 7 ++++++ app/views/discuss_demo/show.html.erb | 2 ++ 6 files changed, 63 insertions(+) create mode 100644 app/controllers/discuss_demo_controller.rb create mode 100644 app/helpers/discuss_demo_helper.rb create mode 100644 app/models/discuss_demo.rb create mode 100644 app/views/discuss_demo/index.html.erb create mode 100644 app/views/discuss_demo/new.html.erb create mode 100644 app/views/discuss_demo/show.html.erb diff --git a/app/controllers/discuss_demo_controller.rb b/app/controllers/discuss_demo_controller.rb new file mode 100644 index 000000000..50f527b39 --- /dev/null +++ b/app/controllers/discuss_demo_controller.rb @@ -0,0 +1,27 @@ +class DiscussDemoController < ApplicationController + def index + @discuss_demo_list = DiscussDemo.order("created_at desc").page(params[:page] || 1).per(10) + end + + def new + + end + + def create + discuss_demo = DiscussDemo.new(:title => params[:discuss_demo][:title],:body =>params[:discuss_demo][:body]) + discuss_demo.save! + redirect_to :controller=>'discuss_demo',:action => 'show',:id => discuss_demo.id + end + + def update + + end + + def delete + + end + + def show + @discuss_demo = DiscussDemo.find(params[:id]) + end +end diff --git a/app/helpers/discuss_demo_helper.rb b/app/helpers/discuss_demo_helper.rb new file mode 100644 index 000000000..4fedaa1a9 --- /dev/null +++ b/app/helpers/discuss_demo_helper.rb @@ -0,0 +1,2 @@ +module DiscussDemoHelper +end diff --git a/app/models/discuss_demo.rb b/app/models/discuss_demo.rb new file mode 100644 index 000000000..cb8b8c1dd --- /dev/null +++ b/app/models/discuss_demo.rb @@ -0,0 +1,4 @@ +class DiscussDemo < ActiveRecord::Base + attr_accessible :title, :body + validates_presence_of :title, :body +end diff --git a/app/views/discuss_demo/index.html.erb b/app/views/discuss_demo/index.html.erb new file mode 100644 index 000000000..f9bee9b54 --- /dev/null +++ b/app/views/discuss_demo/index.html.erb @@ -0,0 +1,21 @@ +

文章列表

+
+ + <% @discuss_demo_list.each do |e| %> + + + + + + + + + <% end %> +
<%= truncate(e.title,:length => 50) %> + <%= textAreailizable truncate(e.body,:length => 500) %>   + + <%= link_to '查看文章',{:controller => 'discuss_demo',:action => 'show',:id=>e.id} %> +
+ <% paginate @discuss_demo_list %> + <%= link_to '新建文章',new_discuss_demo_path %> +
\ No newline at end of file diff --git a/app/views/discuss_demo/new.html.erb b/app/views/discuss_demo/new.html.erb new file mode 100644 index 000000000..9b75805d8 --- /dev/null +++ b/app/views/discuss_demo/new.html.erb @@ -0,0 +1,7 @@ +<%= javascript_include_tag src='/assets/kindeditor/kindeditor' %> +

新建文章

+<%= form_for :discuss_demo do |f| %> + <%= f.text_field :title %> + <%= f.kindeditor :body %> + <%= f.submit :value=> '提交' %> +<% end %> \ No newline at end of file diff --git a/app/views/discuss_demo/show.html.erb b/app/views/discuss_demo/show.html.erb new file mode 100644 index 000000000..600b96589 --- /dev/null +++ b/app/views/discuss_demo/show.html.erb @@ -0,0 +1,2 @@ +

<%= @discuss_demo.title %>

+<%= textAreailizable @discuss_demo.body %> \ No newline at end of file