Skip to content

Commit 7817baf

Browse files
committed
本に関する記事の一覧表示ページを作成
1 parent 4761b9c commit 7817baf

File tree

7 files changed

+62
-1
lines changed

7 files changed

+62
-1
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
class SoTechShaOverviewPageController < CmsController
2+
POSTS_PER_PAGE = 10
3+
4+
def index
5+
offset = params[:offset].to_i
6+
7+
sts_posts_query = BlogPostPage.where(:_permalink, :starts_with, 'sotechsha-')
8+
sts_posts_query.batch_size(POSTS_PER_PAGE).offset(offset)
9+
@sts_posts = sts_posts_query.take(POSTS_PER_PAGE)
10+
11+
total = sts_posts_query.size
12+
13+
if offset > 0
14+
@previous_page = scrivito_path(@obj, offset: offset - POSTS_PER_PAGE)
15+
end
16+
17+
if total > offset + POSTS_PER_PAGE
18+
@next_page = scrivito_path(@obj, offset: offset + POSTS_PER_PAGE)
19+
end
20+
end
21+
22+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
class SoTechShaOverviewPage < Obj
2+
attribute :title, :string
3+
attribute :body, :widgetlist
4+
attribute :child_order, :referencelist
5+
end
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<%= scrivito_medium_dialog do %>
2+
<%= scrivito_details_for "Title" do %>
3+
<%= scrivito_tag :div, @obj, :title %>
4+
<% end %>
5+
<% end %>
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class ="row">
2+
<div class="col-lg-12">
3+
<h1 class="page-header">「Scratchでつくる! たのしむ! プログラミング道場」Webコンテンツ</h1>
4+
</div>
5+
</div>
6+
<% @sts_posts.each do |sts_post| %>
7+
<div class="row">
8+
<div class="col-md-7">
9+
<%= scrivito_image_tag(scrivito_value(sts_post.image), :class => "img-responsive") %>
10+
</div>
11+
<div class="col-md-5">
12+
<h3><%= link_to(scrivito_value(sts_post.title), scrivito_path(sts_post)) %></h3>
13+
<%= content_tag(:p, scrivito_value(sts_post.abstract)) %>
14+
<%= link_to("View Post", scrivito_path(sts_post), :class => "btn btn-primary") %>
15+
</div>
16+
</div>
17+
<hr>
18+
<% end %>
19+
20+
<%= link_to("previous page", @previous_page) if @previous_page %>
21+
<%= link_to("next page", @next_page) if @next_page %>
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
<%= scrivito_thumbnail SoTechShaOverviewPage.description_for_editor, :content %>

config/routes.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Rails.application.routes.draw do
22
# Accsess from CoderDojo Book
3-
get '/sotechsha', to: 'so_tech_sha#index'
3+
get '/sotechsha', to: 'so_tech_sha_overview_page#index'
44
get '/sotechsha/:quiz', to: 'so_tech_sha#quiz'
55

66
# Default Scrivito routes. Adapt them to change the routing of CMS objects.

test/integration/so_tech_sha_test.rb

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ def setup
1717
get "/sotechsha/gazou"
1818
assert_redirected_to "/sotechsha-gazou"
1919
end
20+
21+
test "SoTechShalink should be rendered" do
22+
get "/sotechsha"
23+
#so_tech_sha_overview_page.index がrenderされる
24+
#タイトルが「「Scratchでつくる! たのしむ! プログラミング道場」Webコンテンツ」である
25+
#記事の件数 7件である
26+
end
2027
end

0 commit comments

Comments
 (0)