Skip to content

Commit

Permalink
postに日付追加
Browse files Browse the repository at this point in the history
  • Loading branch information
tadyjp committed Mar 28, 2014
1 parent 80f1d34 commit 094a33b
Show file tree
Hide file tree
Showing 10 changed files with 26 additions and 11 deletions.
5 changes: 3 additions & 2 deletions app/controllers/posts_controller.rb
Expand Up @@ -34,6 +34,7 @@ def show
# GET /posts/new
def new
@post = Post.new
@post.title = '新しい投稿'
end

def fork
Expand Down Expand Up @@ -126,13 +127,13 @@ def slideshow

# 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')
Expand Down
8 changes: 8 additions & 0 deletions app/decorators/post_decorator.rb
Expand Up @@ -19,4 +19,12 @@ def read_time
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
2 changes: 1 addition & 1 deletion app/views/flow/show.html.slim
Expand Up @@ -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})"


6 changes: 4 additions & 2 deletions app/views/posts/_form.html.slim
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion app/views/posts/_show_fragment.html.slim
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion app/views/posts/edit.html.slim
@@ -1,2 +1 @@
h1 編集
= render 'form'
1 change: 0 additions & 1 deletion app/views/posts/new.html.slim
@@ -1,2 +1 @@
h1 新しい投稿
= render 'form'
2 changes: 1 addition & 1 deletion app/views/tags/events.json.jbuilder
@@ -1,5 +1,5 @@
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
5 changes: 5 additions & 0 deletions db/migrate/20140328045902_add_specified_date_to_posts.rb
@@ -0,0 +1,5 @@
class AddSpecifiedDateToPosts < ActiveRecord::Migration
def change
add_column :posts, :specified_date, :date
end
end
5 changes: 3 additions & 2 deletions db/schema.rb
Expand Up @@ -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"
Expand Down Expand Up @@ -40,7 +40,8 @@
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
Expand Down

0 comments on commit 094a33b

Please sign in to comment.