我有一个带有选项卡的页面,我想在单击选项卡时通过ajax呈现不同的部分.我有一些代码,但我认为这不是最有效的方法.我希望是否有人可以帮助我使用已经存在的代码,或者如果有更简单的方法我会非常感激.谢谢!
HTML标签
<li class='StreamTab StreamTabRecent active'>
<%= link_to 'Most Recent', mostrecent_schools_path, :remote => true, :class => 'TabText' %>
</li>
<div id='ContentBody'>
<div id='ajax'></div>
<%= render 'users/microposts', :microposts => @microposts %>
</div>
Run Code Online (Sandbox Code Playgroud)
学校管理员
class SchoolsController < ApplicationController
def mostrecent
@school = School.find_by_slug(request.url.gsub('http://localhost:3000/','')).id
@microposts = @user.microposts.order('created_at DESC').paginate(:per_page => 3, :page => params[:page])
respond_to do |format|
format.html
format.js
end
end
end
Run Code Online (Sandbox Code Playgroud)
最近的JS
$("#ContentBody").html('<%= escape_javascript(render :partial => "users/microposts" )%>');
Run Code Online (Sandbox Code Playgroud)
路线
resources :schools do
collection do
get :mostrecent
end
end
Run Code Online (Sandbox Code Playgroud) 我目前有一个评论模型,在微博下发布,两者都显示在同一页面上.问题是两者都显示在同一页面上,并且两者都是分页的,我试图用facebook方法进行微观测量.以下是以下问题:
两个分页的链接变成了这个href="/users/2?page=2"而不是href="/users/2/micropost?page=2"或href="/users/2/comment?page=2".我不确定如何解决这个问题.这是我的一些代码.所有建议都非常感谢!
Micropost渲染HTML
<table class="microposts">
<% if microposts.any? %>
<%= render microposts %>
<%= will_paginate microposts, :page_links => false %>
<% else %>
<div class="EmptyContainer"><span class='Empty'>Add a thread!</span></div>
<% end %>
</table>
Run Code Online (Sandbox Code Playgroud)
评论部分HTML
<div id='CommentContainer-<%= micropost.id%>' class='CommentContainer Condensed2'>
<div class='Comment'>
<%= render :partial => "comments/form", :locals => { :micropost => micropost } %>
</div>
<div id='comments'>
<% comments = micropost.comments.paginate(:per_page => 5, :page => params[:page]) %>
<%= render comments %>
<%= will_paginate comments, :class …Run Code Online (Sandbox Code Playgroud) 我目前有一个显示微博列表的页面,该页面还包括几个标签,如Most Recent Most Discussed Most Viewed.我想知道如何在不刷新整个页面和通过ajax的情况下呈现微博的不同类型的列表顺序的最佳方法.我不确定该如何去做,但我愿意学习是否有人借给我帮助.谢谢 :).到目前为止,我有这么多.
页面HTML
<div id='ContentHeader'>
<%= render 'microposts/new' %>
<div class='StreamTabContainer'>
<ul class='StreamTabs'>
<li class='StreamTab StreamTabRecent active'>
<%= link_to 'Most Recent', some_path, :remote => true, :class => 'TabText' %>
</li>
<li class='StreamTab StreamTabDiscussed'>
<%= link_to 'Most Discussed', some_path, :remote => true, :class => 'TabText' %>
</li>
<li class='StreamTab StreamTabViews '>
<%= link_to 'Most Views', some_path, :remote => true, :class => 'TabText' %>
</li>
<li class='StreamTab StreamTabRated'>
<%= link_to 'Highest Rated', some_path, :remote => …Run Code Online (Sandbox Code Playgroud)