Commit 5eea6eac by tady

tagページ

parent 97f13919
# 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;
}
// 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
skip_before_action :require_login
layout 'welcome'
def top
if user_signed_in?
......
......@@ -3,6 +3,7 @@ require 'nkf'
class PostsController < ApplicationController
before_action :set_post, only: [:show, :edit, :update, :destroy]
before_action :require_login
layout 'app'
include ApplicationHelper
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
belongs_to :author, class_name: 'User'
has_many :comments
default_scope { order(:updated_at => :desc) }
# Named scope
scope :search, (lambda do |query|
_where_list = includes(:author, :tags)
......
......@@ -3,4 +3,6 @@ class Tag < ActiveRecord::Base
has_many :posts, through: :post_tags
has_ancestry
default_scope { order(:updated_at => :desc) }
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 @@
<%### Post meta ###%>
<% @post.tags.each do |tag| %>
<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>
<% end %>
<span class="label label-success">
......
<div class="app">
<%= render partial: 'partials/app_header' %>
<div class="container">
<h1>新しい投稿</h1>
<%= render 'form' %>
</div><!--/.container-->
<hr>
<footer>
</footer>
</div>
<h1>新しい投稿</h1>
<%= render 'form' %>
<div class="app">
<%= render partial: 'partials/app_header' %>
<div class="container">
<div class="row">
<div class="row">
<div class="col-xs-6 col-md-4" id="sidebar" role="navigation">
......@@ -43,14 +36,5 @@
</div><!--/span-->
</div><!--/row-->
</div><!--/.container-->
</div>
<% content_for :footer_js do %>
<script type="text/javascript">
</div><!--/row-->
</script>
<% end %>
<div class="app">
<%= render partial: 'partials/app_header' %>
<div class="container">
<h1>新しい投稿</h1>
<%= render 'form' %>
</div><!--/.container-->
<hr>
<footer>
</footer>
</div>
<h1>新しい投稿</h1>
<%= render 'form' %>
<div class="app">
<%= render partial: 'partials/app_header' %>
<div class="container">
<div class="row">
<div class="row">
<div id="xxxxxxxx">
<%= render partial: 'posts/show_fragment' %>
</div>
</div><!--/row-->
<hr>
</div><!--/.container-->
</div>
</div><!--/row-->
<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
root 'home#top', as: 'root'
post 'posts/preview' => 'posts#preview'
......@@ -9,6 +10,8 @@ Rendezvous::Application.routes.draw do
post 'posts/:id/comment' => 'posts#comment', as: 'comment_post'
resources :posts
get 'tags/:name' => 'tags#show', as: 'show_tag'
devise_for :users, controllers: { omniauth_callbacks: 'users/omniauth_callbacks' }
# 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