Skip to content

Commit

Permalink
活動訊息:過往清單
Browse files Browse the repository at this point in the history
  • Loading branch information
lulalala committed Jun 7, 2016
1 parent f26a73d commit 6eb44e1
Show file tree
Hide file tree
Showing 6 changed files with 46 additions and 15 deletions.
13 changes: 6 additions & 7 deletions app/controllers/groups_controller.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class GroupsController < ApplicationController
before_action :set_fountain, only: [:show]

# GET /groups/1
def show
end
@group = Group.find(params[:id])
@notice = @group.notices.order(id: :desc).first

private
# Use callbacks to share common setup or constraints between actions.
def set_fountain
@group = Group.find(params[:id])
if @notice
redirect_to url_for([@group, @notice])
else
end
end
end
11 changes: 11 additions & 0 deletions app/controllers/notices_controller.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
class NoticesController < ApplicationController
def index
@group = Group.find(params[:group_id])
@notices = @group.notices.order(id: :desc)
end

def show
@group = Group.find(params[:group_id])
@notice = @group.notices.find(params[:id])
end
end
8 changes: 1 addition & 7 deletions app/views/groups/show.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1 @@
<h1><%= @group.name %></h1>

<% notice = @group.notices.order(id: :desc).first %>
<% if notice %>
<h1><%= notice.title %></h1>
<%= notice.body.html_safe %>
<% end %>
<h2><%= @group.name %>目前沒有活動訊息</h2>
14 changes: 14 additions & 0 deletions app/views/notices/index.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<h1><%= @group.name %>過往活動訊息</h1>

<table class="table">
<% @notices.each do |n| %>
<tr>
<td>
<%= link_to n.title, [@group, n] %>
</td>
<td>
<%= n.created_at.strftime('%d/%m/%Y') %>
</td>
</tr>
<% end %>
</table>
11 changes: 11 additions & 0 deletions app/views/notices/show.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<h2><%= @group.name %></h2>

<% if @notice %>
<h1>
<%= @notice.title %>
</h1>

<%= @notice.body.html_safe %>
<%= link_to "#{@group.name}過往活動訊息", [@group, :notices] %>
<% end %>
4 changes: 3 additions & 1 deletion config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@
devise_for :users
resources :users

resources :groups, only: [:show]
resources :groups, only: [:show] do
resources :notices, only: [:index, :show]
end
resources :posts, only: [:show]
resources :fountains, only: [:index, :show]
resources :schedules, only: [:index]
Expand Down

0 comments on commit 6eb44e1

Please sign in to comment.