Commit 6c4e5dc4 by tady

ログアウト

parent 2bade347
...@@ -3,4 +3,12 @@ class ApplicationController < ActionController::Base ...@@ -3,4 +3,12 @@ class ApplicationController < ActionController::Base
# For APIs, you may want to use :null_session instead. # For APIs, you may want to use :null_session instead.
protect_from_forgery with: :exception protect_from_forgery with: :exception
def require_login
unless user_signed_in?
flash[:alert] = 'You need Login!'
redirect_to root_path
end
end
end end
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, except: [:index]
include ApplicationHelper include ApplicationHelper
......
...@@ -3,7 +3,7 @@ module PostsHelper ...@@ -3,7 +3,7 @@ module PostsHelper
# @param {ActiveRecord::Relation} node # @param {ActiveRecord::Relation} node
def h_display_tree(node) def h_display_tree(node)
_html = '<ul>' _html = '<ul>'
_html << %Q{<li><a href="#{ root_path(q: '#' + node.name) }">#{node.name}<a/></li>} _html << %Q{<li><a href="#{ root_path(q: '#' + node.name) }">#{node.name}</a></li>}
node.children.each do |_child| node.children.each do |_child|
_html << h_display_tree(_child) _html << h_display_tree(_child)
end end
......
...@@ -17,7 +17,7 @@ ...@@ -17,7 +17,7 @@
<div class="list-group"> <div class="list-group">
<% Tag.roots.each do |root| %> <% Tag.roots.each do |root| %>
<%= h_display_tree(root) %> <%= h_display_tree(root) %>
<% end %> <% end %>
</div> </div>
......
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