質問編集履歴
1
コード抜粋を追記しました。
test
CHANGED
File without changes
|
test
CHANGED
@@ -17,3 +17,117 @@
|
|
17
17
|
ajaxでレンダリングした要素にjqueryを適用させる方法が見つけられず
|
18
18
|
|
19
19
|
ご助力いただきたいです。よろしくお願いいたします。
|
20
|
+
|
21
|
+
|
22
|
+
|
23
|
+
(追記)
|
24
|
+
|
25
|
+
ご指摘いただきありがとうございます。仰る通りです。以下コード抜粋です。
|
26
|
+
|
27
|
+
|
28
|
+
|
29
|
+
__index.html.erb__
|
30
|
+
|
31
|
+
```erb
|
32
|
+
|
33
|
+
<div class="index">
|
34
|
+
|
35
|
+
<article class="articles">
|
36
|
+
|
37
|
+
<%= render 'article_lists' %>
|
38
|
+
|
39
|
+
</article>
|
40
|
+
|
41
|
+
<div class="more">
|
42
|
+
|
43
|
+
<%= link_to_next_page @articles, 'もっと見る', remote: true, id: 'view-more' %>
|
44
|
+
|
45
|
+
</div>
|
46
|
+
|
47
|
+
</div>
|
48
|
+
|
49
|
+
```
|
50
|
+
|
51
|
+
|
52
|
+
|
53
|
+
___article_lists.html.erb__
|
54
|
+
|
55
|
+
```erb
|
56
|
+
|
57
|
+
<% @articles.each do |article| %>
|
58
|
+
|
59
|
+
<section class="article">
|
60
|
+
|
61
|
+
<div class="photos preview-slick">
|
62
|
+
|
63
|
+
<% if article.photos.present? %>
|
64
|
+
|
65
|
+
<% article.photos.each do |photo| %>
|
66
|
+
|
67
|
+
<div class="photo">
|
68
|
+
|
69
|
+
<%= image_tag photo, class: 'article-photo' %>
|
70
|
+
|
71
|
+
</div>
|
72
|
+
|
73
|
+
<% end %>
|
74
|
+
|
75
|
+
<% else %>
|
76
|
+
|
77
|
+
<div class="photo">
|
78
|
+
|
79
|
+
<%= image_tag 'no_image.png', class: 'article-photo' %>
|
80
|
+
|
81
|
+
</div>
|
82
|
+
|
83
|
+
<% end %>
|
84
|
+
|
85
|
+
</div>
|
86
|
+
|
87
|
+
<div class="article-caption">
|
88
|
+
|
89
|
+
<h1><%= article.name %></h1>
|
90
|
+
|
91
|
+
</div>
|
92
|
+
|
93
|
+
</section>
|
94
|
+
|
95
|
+
<% end %>
|
96
|
+
|
97
|
+
```
|
98
|
+
|
99
|
+
__index.js__
|
100
|
+
|
101
|
+
```js
|
102
|
+
|
103
|
+
$('.articles').append("<%= escape_javascript(render 'article_lists', object: @articles) %>");
|
104
|
+
|
105
|
+
$("#view-more").replaceWith("<%= escape_javascript(
|
106
|
+
|
107
|
+
link_to_next_page(@articles, 'もっと見る', remote: true, id: 'view_more')) %>");
|
108
|
+
|
109
|
+
|
110
|
+
|
111
|
+
```
|
112
|
+
|
113
|
+
__articles_controller.rb__
|
114
|
+
|
115
|
+
```ruby
|
116
|
+
|
117
|
+
def index
|
118
|
+
|
119
|
+
@articles = Article.includes({photos_attachments: :blob}).where(created_at: Time.zone.now.all_day)
|
120
|
+
|
121
|
+
@articles = Kaminari.paginate_array(@articles).page(params[:page]).per(32)
|
122
|
+
|
123
|
+
end
|
124
|
+
|
125
|
+
```
|
126
|
+
|
127
|
+
__article.rb__
|
128
|
+
|
129
|
+
```ruby
|
130
|
+
|
131
|
+
paginates_per 32
|
132
|
+
|
133
|
+
```
|