Commit 6373022d by tady

Merge pull request #25 from tadyjp/wip/140228_tag_manager

tagページ
parents 97f13919 5eea6eac
# Place all the behaviors and hooks related to the matching controller here.
# All this logic will automatically be available in application.js.
# You can use CoffeeScript in this file: http://coffeescript.org/
body[class^="posts-"] { body[class^="posts-"],
body[class^="tags-"] {
padding-top: 70px; padding-top: 70px;
} }
// Place all the styles related to the tags controller here.
// They will automatically be included in application.css.
// You can use Sass (SCSS) here: http://sass-lang.com/
class HomeController < ApplicationController class HomeController < ApplicationController
skip_before_action :require_login skip_before_action :require_login
layout 'welcome'
def top def top
if user_signed_in? if user_signed_in?
......
...@@ -3,6 +3,7 @@ require 'nkf' ...@@ -3,6 +3,7 @@ require 'nkf'
class PostsController < ApplicationController class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy] before_action :set_post, only: [:show, :edit, :update, :destroy]
before_action :require_login before_action :require_login
layout 'app'
include ApplicationHelper include ApplicationHelper
include RV::Mailer include RV::Mailer
......
class TagsController < ApplicationController
layout 'app'
def show
@tag = Tag.find_by(tag_params)
@posts = @tag.posts
end
private
def tag_params
params.permit(:name).to_hash
end
end
module TagsHelper
end
...@@ -4,6 +4,8 @@ class Post < ActiveRecord::Base ...@@ -4,6 +4,8 @@ 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) }
# Named scope # Named scope
scope :search, (lambda do |query| scope :search, (lambda do |query|
_where_list = includes(:author, :tags) _where_list = includes(:author, :tags)
......
...@@ -3,4 +3,6 @@ class Tag < ActiveRecord::Base ...@@ -3,4 +3,6 @@ class Tag < ActiveRecord::Base
has_many :posts, through: :post_tags has_many :posts, through: :post_tags
has_ancestry has_ancestry
default_scope { order(:updated_at => :desc) }
end end
<!DOCTYPE html>
<html lang="ja">
<head>
<title>Rendezvous</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<%= stylesheet_link_tag "application", media: "all" %>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap.min.css">
<!-- Optional theme -->
<link rel="stylesheet" href="//netdna.bootstrapcdn.com/bootstrap/3.0.2/css/bootstrap-theme.min.css">
<%= render_style %>
<%= csrf_meta_tags %>
</head>
<body class="<%= params[:controller] %>-<%= params[:action] %>">
<%= render partial: 'partials/header_notifications' %>
<div class="app">
<%= render partial: 'partials/app_header' %>
<div class="container">
<%= yield %>
</div><!--/.container-->
</div>
<script src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.5.2/underscore-min.js"></script>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.2/js/bootstrap.min.js"></script>
<script type="text/javascript">
window.RV = window.RV || {};
window.RV.AllTags = JSON.parse('<%= raw Tag.all.pluck(:name).to_json %>');
</script>
<footer>
<div class="container">
<a href="https://github.com/tadyjp/rendezvous">Github</a>
|
<a href="https://twitter.com/tady_jp">@tady_jp</a>
</div>
</footer>
<%= javascript_include_tag "application" %>
<%= yield :footer_js %>
</body>
</html>
...@@ -10,7 +10,7 @@ ...@@ -10,7 +10,7 @@
<%### Post meta ###%> <%### Post meta ###%>
<% @post.tags.each do |tag| %> <% @post.tags.each do |tag| %>
<span class="label label-info"> <span class="label label-info">
<a href="<%= posts_path(q: "##{tag.name}") %>">#<%= tag.name %></a> <a href="<%= show_tag_path(name: url_encode(tag.name)) %>">#<%= tag.name %></a>
</span> </span>
<% end %> <% end %>
<span class="label label-success"> <span class="label label-success">
......
<div class="app"> <h1>新しい投稿</h1>
<%= render partial: 'partials/app_header' %>
<div class="container">
<h1>新しい投稿</h1>
<%= render 'form' %>
</div><!--/.container-->
<hr>
<footer>
</footer>
</div>
<%= render 'form' %>
<div class="row">
<div class="app"> <div class="col-xs-6 col-md-4" id="sidebar" role="navigation">
<%= render partial: 'partials/app_header' %> <ul class="nav nav-tabs">
<li class="active"><a href="#tab-list" data-toggle="tab">List</a></li>
<li><a href="#tab-tree" data-toggle="tab">Tag Tree</a></li>
</ul>
<div class="container"> <div class="tab-content">
<div class="tab-pane active" id="tab-list">
<div class="row"> <div class="list-group">
<% @posts.each_with_index do |post, i| %>
<div class="col-xs-6 col-md-4" id="sidebar" role="navigation"> <a href="#" data-post-id="<%= post.id %>" class="list-group-item post-list"><%= post.title %></a>
<% end %>
<ul class="nav nav-tabs">
<li class="active"><a href="#tab-list" data-toggle="tab">List</a></li>
<li><a href="#tab-tree" data-toggle="tab">Tag Tree</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="tab-list">
<div class="list-group">
<% @posts.each_with_index do |post, i| %>
<a href="#" data-post-id="<%= post.id %>" class="list-group-item post-list"><%= post.title %></a>
<% end %>
</div>
</div><!-- /.tab-pane -->
<div class="tab-pane" id="tab-tree">
<% cache('tag-tree', :expires_in => 1.hour) do %>
<div class="list-group">
<% Tag.roots.each do |root| %>
<%= h_display_tree(root) %>
<% end %>
</div>
<% end %>
</div><!-- /.tab-pane -->
</div><!-- /.tab-content -->
</div><!--/span-->
<div class="col-xs-12 col-sm-6 col-md-8">
<div id="list_post">
<p id="posts-placeholder" style="color:#aaa;font-size:30px">&lt;-- Select a post...</p>
</div> </div>
</div><!-- /.tab-pane -->
<div class="tab-pane" id="tab-tree">
<% cache('tag-tree', :expires_in => 1.hour) do %>
<div class="list-group">
<% Tag.roots.each do |root| %>
<%= h_display_tree(root) %>
<% end %>
</div>
<% end %>
</div><!-- /.tab-pane -->
</div><!-- /.tab-content -->
</div><!--/span--> </div><!--/span-->
</div><!--/row--> <div class="col-xs-12 col-sm-6 col-md-8">
</div><!--/.container--> <div id="list_post">
<p id="posts-placeholder" style="color:#aaa;font-size:30px">&lt;-- Select a post...</p>
</div>
</div> </div><!--/span-->
<% content_for :footer_js do %> </div><!--/row-->
<script type="text/javascript">
</script>
<% end %>
<div class="app"> <h1>新しい投稿</h1>
<%= render partial: 'partials/app_header' %>
<div class="container">
<h1>新しい投稿</h1>
<%= render 'form' %>
</div><!--/.container-->
<hr>
<footer>
</footer>
</div>
<%= render 'form' %>
<div class="row">
<div class="app"> <div id="xxxxxxxx">
<%= render partial: 'posts/show_fragment' %>
<%= render partial: 'partials/app_header' %> </div>
</div><!--/row-->
<div class="container">
<div class="row">
<div id="xxxxxxxx">
<%= render partial: 'posts/show_fragment' %>
</div>
</div><!--/row-->
<hr>
</div><!--/.container-->
</div>
<div class="row">
<h1><%= @tag.name %>についてのページ</h1>
<div class="col-xs-8">
<div class="panel panel-default">
<div class="panel-heading">
<%= @tag.name %>」とは
</div>
<div class="panel-body">
まだ「<%= @tag.name %>」の情報がありません。
</div>
</div>
</div>
<div class="col-xs-4">
<div class="list-group">
<h2><small><%= @tag.name %>」のタグが付いた記事</small></h2>
<% @posts.each_with_index do |post, i| %>
<a href="<%= post_path(post) %>" class="list-group-item post-list"><%= post.title %></a>
<% end %>
</div>
</div>
</div><!--/row-->
Rendezvous::Application.routes.draw do Rendezvous::Application.routes.draw do
root 'home#top', as: 'root' root 'home#top', as: 'root'
post 'posts/preview' => 'posts#preview' post 'posts/preview' => 'posts#preview'
...@@ -9,6 +10,8 @@ Rendezvous::Application.routes.draw do ...@@ -9,6 +10,8 @@ Rendezvous::Application.routes.draw do
post 'posts/:id/comment' => 'posts#comment', as: 'comment_post' post 'posts/:id/comment' => 'posts#comment', as: 'comment_post'
resources :posts resources :posts
get 'tags/:name' => 'tags#show', as: 'show_tag'
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' } devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
# The priority is based upon order of creation: first created -> highest priority. # The priority is based upon order of creation: first created -> highest priority.
......
require 'spec_helper'
describe TagsController do
describe "GET 'show'" do
pending '...'
end
end
require 'spec_helper'
# Specs in this file have access to a helper object that includes
# the TagsHelper. For example:
#
# describe TagsHelper do
# describe "string concat" do
# it "concats two strings with spaces" do
# expect(helper.concat_strings("this","that")).to eq("this that")
# end
# end
# end
describe TagsHelper do
pending "add some examples to (or delete) #{__FILE__}"
end
require 'spec_helper'
describe "tags/show.html.erb" do
pending "add some examples to (or delete) #{__FILE__}"
end
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