Commit 5480173c by tady

Merge pull request #72 from tadyjp/wip/140328_post_date

postに日付追加
parents 80f1d343 094a33b1
......@@ -34,6 +34,7 @@ class PostsController < ApplicationController
# GET /posts/new
def new
@post = Post.new
@post.title = '新しい投稿'
end
def fork
......@@ -126,13 +127,13 @@ class PostsController < ApplicationController
# Use callbacks to share common setup or constraints between actions.
def set_post
@post = Post.find(params[:id])
@post = Post.find(params[:id]).decorate
end
# Never trust parameters from the scary internet, only allow the white list through.
def post_params
@post_params ||= begin
_param_hash = params.require(:post).permit(:title, :body, :tags, :is_draft).to_hash
_param_hash = params.require(:post).permit(:title, :body, :tags, :is_draft, :specified_date).to_hash
# tags_text == 'Javascript,Ruby'
tags_text = _param_hash.delete('tags')
......
......@@ -19,4 +19,12 @@ class PostDecorator < Draper::Decorator
end
end
def display_date
if model.specified_date
model.specified_date.strftime('%Y-%m-%d')
else
model.updated_at.strftime('%Y-%m-%d')
end
end
end
......@@ -23,6 +23,6 @@
h2.panel-title 最近投稿したユーザー(調整中)
.panel-body.list-group
- User.post_recently.limit(10).each_with_index do |author, i|
a.list-group-item.post-list data-author-id=author.id href=search_path(q: "@#{author.nickname}") = author.name
a.list-group-item.post-list data-author-id=author.id href=search_path(q: "@#{author.nickname}") = "#{author.name} (@#{author.nickname})"
......@@ -9,7 +9,7 @@
- @post.errors.full_messages.each do |msg|
li= msg
.row
.col-xs-10
.col-xs-9
.field
.input-group
span.input-group-addon= f.label :title
......@@ -20,12 +20,14 @@
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(',')
.col-xs-2
.col-xs-3
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, "下書き保存"
p.actions
= f.date_select :specified_date
br/
.row
......
......@@ -12,7 +12,7 @@
a href=(posts_path(q: "@#{@post.author.name}"))
| @#{@post.author.name}
span.label.label-danger
a href=(posts_path(q: "date:#{@post.updated_at.strftime('%Y-%m-%d')}")) = @post.updated_at.strftime('%Y-%m-%d')
a href=(posts_path(q: "date:#{@post.display_date}")) = @post.display_date
.btn-group.pull-right style=("margin: -7px -12px 0 0;")
a.btn.btn-primary href=edit_post_path(@post)
span.glyphicon.glyphicon-pencil
......
h1 新しい投稿
= render 'form'
json.array!(@tag.posts) do |post|
json.extract! post, :title
json.url post_url(post)
json.start post.created_at
json.start post.specified_date || post.created_at
end
class AddSpecifiedDateToPosts < ActiveRecord::Migration
def change
add_column :posts, :specified_date, :date
end
end
......@@ -11,7 +11,7 @@
#
# It's strongly recommended that you check this file into your version control system.
ActiveRecord::Schema.define(version: 20140320043116) do
ActiveRecord::Schema.define(version: 20140328045902) do
create_table "comments", force: true do |t|
t.integer "author_id"
......@@ -40,7 +40,8 @@ ActiveRecord::Schema.define(version: 20140320043116) do
t.integer "author_id"
t.datetime "created_at"
t.datetime "updated_at"
t.boolean "is_draft", default: false
t.boolean "is_draft", default: false
t.date "specified_date"
end
add_index "posts", ["is_draft"], name: "index_posts_on_is_draft", using: :btree
......
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