前提・実現したいこと
このページを参考に実装したのですが、無限スクロールされません。
発生している問題・エラーメッセージ
エラーメッセージ等は起きていません。
該当のソースコード
post.js.coffee
$(document).ready -> $("#posts .page").infinitescroll navSelector: "nav.pagination" # selector for the paged navigation (it will be hidden) nextSelector: "nav.pagination a[rel=next]" # selector for the NEXT link (to page 2) itemSelector: "#posts tr.post" # selector for all items you'll retrieve
posts/indx.html.erb
<p id="notice"><%= notice %></p> <h1>Listing Posts</h1> <table id="posts"> <thead> <tr> <th>Title</th> <th>Author</th> <th>Body</th> <th colspan="3"></th> </tr> </thead> <tbody class="page"> <%= render @posts %> </tbody> </table> <br> <%= link_to 'New Post', new_post_path %> <%= paginate @posts %>
_post.html.erb
<tr class="post"> <td><%= post.title %></td> <td><%= post.author %></td> <td><%= post.body %></td> <td><%= link_to 'Show', post %></td> <td><%= link_to 'Edit', edit_post_path(post) %></td> <td><%= link_to 'Destroy', post, method: :delete, data: { confirm: 'Are you sure?' } %></td> </tr>
index.js.erb
$("#posts").append("<tbody class='page'><%= escape_javascript(render(@posts)) %></tbody>");
posts_controller.rb
class PostsController < ApplicationController before_action :set_post, only: [:show, :edit, :update, :destroy] # GET /posts # GET /posts.json def index @posts = Post.order(:created_at).page(params[:page]) end # GET /posts/1 # GET /posts/1.json def show end # GET /posts/new def new @post = Post.new end # GET /posts/1/edit def edit end # POST /posts # POST /posts.json def create @post = Post.new(post_params) respond_to do |format| if @post.save format.html { redirect_to @post, notice: 'Post was successfully created.' } format.json { render :show, status: :created, location: @post } else format.html { render :new } format.json { render json: @post.errors, status: :unprocessable_entity } end end end # PATCH/PUT /posts/1 # PATCH/PUT /posts/1.json def update respond_to do |format| if @post.update(post_params) format.html { redirect_to @post, notice: 'Post was successfully updated.' } format.json { render :show, status: :ok, location: @post } else format.html { render :edit } format.json { render json: @post.errors, status: :unprocessable_entity } end end end # DELETE /posts/1 # DELETE /posts/1.json def destroy @post.destroy respond_to do |format| format.html { redirect_to posts_url, notice: 'Post was successfully destroyed.' } format.json { head :no_content } end end private # Use callbacks to share common setup or constraints between actions. def set_post @post = Post.find(params[:id]) end # Never trust parameters from the scary internet, only allow the white list through. def post_params params.require(:post).permit(:title, :author, :body) end end
試したこと
curlの取得先をhttps://unpkg.com/infinite-scroll@3.0.4/dist/infinite-scroll.pkgd.jsに修正して実施しました。
補足情報(FW/ツールのバージョンなど)
rails4 or 5
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。