How do I get this page to paginate using kaminari? I need help with this badly. I don't know what to do. Just get me some way so that all the posts will only be 15 per page. I want the show page to be paginated not the index page.
This is the website I built. http://duelingpets.net/maintopics/9/subtopics/4
This is my show page for my subtopics page that is nested under maintopics
<p id="notice"><%= notice %></p>
This pages shows the current topic name of a subtopic
<h1 class="forumheader"><%= @subtopic.topicname %></h1>
<br><!---Gives space to start the narratives--->
<div class="narrativecontainer">
<table>
<tr>
<td><%= @subtopic.topicname %></td>
</tr>
<tr>
<td>by: <%= @subtopic.user.vname %></td>
</tr>
<tr>
<td><pre class="narrative_pre"><%= @subtopic.description %></pre></td>
</tr>
</table>
<br>
<% @subtopic.narratives.each do |narrative| %>
<div class="outer">
<table>
<tr>
<td>re:<%= narrative.subtopic.topicname %></td>
<% if current_user && (current_user.id == narrative.user_id || current_user.admin?)%>
<td><%= button_to 'Edit', edit_subtopic_narrative_path(@subtopic, narrative), method: :get %></td>
<td><%= button_to 'Destroy', [@subtopic, narrative], method: :delete, data: { confirm: 'Are you sure?' } %></td>
<% end %>
</tr>
<tr>
<td>by: <%= narrative.user.vname %><%#= subtopic.description %></td>
</tr>
</table>
</div>
<div class="outer">
<pre class="narrative_pre"><%= narrative.story %></pre>
</div>
<br>
<% end %>
</div>
<br>
<% if current_user %>
<p><%= link_to 'New Narrative', new_subtopic_narrative_path(@subtopic) %></p>
<br>
<% end %>
<p><%= link_to 'Back', tcontainer_maintopic_path(@maintopic.tcontainer_id, @maintopic) %></p>
This my subtopics controller.
class SubtopicsController < ApplicationController
# GET /subtopics
# GET /subtopics.json
#before_filter :load_forum
before_filter :load_topic, :only => [:edit, :update, :show, :destroy]
before_filter :load_maintopic, :only =>[:create, :index, :new]
def index
if current_user && current_user.admin?
@subtopics = @maintopic.subtopics.all
else
render "public/404"
end
end
# GET /subtopics/1
# GET /subtopics/1.json
def show
#@subtopic.narratives.page(params[:page])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @subtopic }
end
end
# GET /subtopics/new
# GET /subtopics/new.json
def new
if current_user
@user = current_user.id
@subtopic = @maintopic.subtopics.build
@subtopic.user_id = @user
else
redirect_to root_url
end
end
# GET /subtopics/1/edit
def edit
end
# POST /subtopics
# POST /subtopics.json
def create
if current_user
@user = current_user.id
@subtopic = @maintopic.subtopics.new(params[:subtopic])
@subtopic.user_id = @user
if !(@subtopic.maintopic_id == @maintopic.id) #Prevents a subtopic from being assigned data to a maintopic that doesn't match
redirect_to @maintopic
return
end
@subtopic.created_on = Time.now
@subtopic.save
#if @subtopic.save
# redirect_to @maintopic.subtopic
#else
# render "new";
#end
redirect_to maintopic_subtopic_path(@maintopic, @subtopic)
else
redirect_to root_url
end
end
# PUT /subtopics/1
# PUT /subtopics/1.json
def update
respond_to do |format|
if @subtopic.update_attributes(params[:subtopic])
format.html { redirect_to maintopic_subtopic_path(@subtopic.maintopic_id, @subtopic.id), notice: 'Subtopic was successfully updated.' }
format.json { head :no_content }
else
format.html { render action: "edit" }
format.json { render json: @subtopic.errors, status: :unprocessable_entity }
end
end
end
#raise
# DELETE /subtopics/1
# DELETE /subtopics/1.json
def destroy
@subtopic.destroy
respond_to do |format|
format.html { redirect_to tcontainer_maintopic_path(@maintopic.tcontainer_id, @maintopic.id) }
format.json { head :no_content }
end
end
private
def load_topic
@subtopic = Subtopic.find(params[:id])
@maintopic = Maintopic.find(@subtopic.maintopic_id)
@content = Maintopic.find(params[:maintopic_id])
if @content.id != @maintopic.id
# raise "I been tampered with and should redirect to the root page"
redirect_to root_url
end
end
def load_maintopic
@maintopic = Maintopic.find(params[:maintopic_id])
end
end