Commit b930d512 by tady

下書き保存機能

parent 3f0451f8
...@@ -2,6 +2,6 @@ class FlowController < ApplicationController ...@@ -2,6 +2,6 @@ class FlowController < ApplicationController
before_action :require_login before_action :require_login
def show def show
@posts = Post.order(updated_at: :desc).limit(20).decorate @posts = Post.where(is_draft: false).order(updated_at: :desc).limit(20).decorate
end end
end end
...@@ -132,7 +132,7 @@ class PostsController < ApplicationController ...@@ -132,7 +132,7 @@ class PostsController < ApplicationController
# Never trust parameters from the scary internet, only allow the white list through. # Never trust parameters from the scary internet, only allow the white list through.
def post_params def post_params
@post_params ||= begin @post_params ||= begin
_param_hash = params.require(:post).permit(:title, :body, :tags).to_hash _param_hash = params.require(:post).permit(:title, :body, :tags, :is_draft).to_hash
# tags_text == 'Javascript,Ruby' # tags_text == 'Javascript,Ruby'
tags_text = _param_hash.delete('tags') tags_text = _param_hash.delete('tags')
......
...@@ -4,7 +4,7 @@ class Post < ActiveRecord::Base ...@@ -4,7 +4,7 @@ class Post < ActiveRecord::Base
belongs_to :author, class_name: 'User' belongs_to :author, class_name: 'User'
has_many :comments has_many :comments
default_scope { order(:updated_at => :desc) } # default_scope { where(is_draft: false).order(:updated_at => :desc) }
# Named scope # Named scope
scope :search, (lambda do |query| scope :search, (lambda do |query|
......
...@@ -14,17 +14,18 @@ ...@@ -14,17 +14,18 @@
.input-group .input-group
span.input-group-addon= f.label :title span.input-group-addon= f.label :title
= f.text_field :title, class: 'form-control mod-mdEditor-title' = f.text_field :title, class: 'form-control mod-mdEditor-title'
.col-xs-2
.actions
= f.submit class: 'btn btn-primary js-disable-confirm-unload', id: 'save_button'
.row
.col-xs-8
.field .field
.input-group .input-group
span.input-group-addon= f.label :tags span.input-group-addon= f.label :tags
= hidden_field :post, :tags, class: 'mod-mdEditor-tags', style: 'width:300px', value: @post.tags.map{ |_tag| _tag.name }.join(',') = hidden_field :post, :tags, class: 'mod-mdEditor-tags', style: 'width:300px', value: @post.tags.map{ |_tag| _tag.name }.join(',')
.col-xs-4
.col-xs-2
p.actions
= f.submit class: 'btn btn-primary js-disable-confirm-unload', id: 'save_button'
p.actions
= f.check_box :is_draft
= f.label :is_draft, "下書き保存"
br/ br/
.row .row
...@@ -36,6 +37,7 @@ ...@@ -36,6 +37,7 @@
.text-box.body.viewer.github.mod-mdEditor-preview .text-box.body.viewer.github.mod-mdEditor-preview
input#fileupload data-url="/apis/file_receiver" multiple="" name="files[]" style="display:none" type="file" / input#fileupload data-url="/apis/file_receiver" multiple="" name="files[]" style="display:none" type="file" /
- content_for :footer_js do - content_for :footer_js do
javascript: javascript:
$.setConfirmUnload(); $.setConfirmUnload();
...@@ -46,3 +48,10 @@ input#fileupload data-url="/apis/file_receiver" multiple="" name="files[]" style ...@@ -46,3 +48,10 @@ input#fileupload data-url="/apis/file_receiver" multiple="" name="files[]" style
$input: $('#fileupload'), $input: $('#fileupload'),
$textarea: $('.mod-mdEditor-body') $textarea: $('.mod-mdEditor-body')
}); });
// 下書き保存
$('.btn-save-draft').on('click', function(e){
e.preventDefault();
var val = $('.mod-mdEditor-body').val();
console.log(val);
});
class AddIsDraftToPosts < ActiveRecord::Migration
def change
add_column :posts, :is_draft, :boolean, default: false
add_index :posts, :is_draft
end
end
...@@ -11,7 +11,7 @@ ...@@ -11,7 +11,7 @@
# #
# It's strongly recommended that you check this file into your version control system. # It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140302053916) do ActiveRecord::Schema.define(version: 20140318040809) do
create_table "comments", force: true do |t| create_table "comments", force: true do |t|
t.integer "author_id" t.integer "author_id"
...@@ -40,8 +40,11 @@ ActiveRecord::Schema.define(version: 20140302053916) do ...@@ -40,8 +40,11 @@ ActiveRecord::Schema.define(version: 20140302053916) do
t.integer "author_id" t.integer "author_id"
t.datetime "created_at" t.datetime "created_at"
t.datetime "updated_at" t.datetime "updated_at"
t.boolean "is_draft", default: false
end end
add_index "posts", ["is_draft"], name: "index_posts_on_is_draft", using: :btree
create_table "tags", force: true do |t| create_table "tags", force: true do |t|
t.string "name" t.string "name"
t.datetime "created_at" t.datetime "created_at"
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment