Rails PJAX 加载部分而不是 html 文件
我正在 Rails 中使用 PJAX 创建一个基于选项卡的菜单。
我有 PJAX 工作,当我加载正常页面时,它会在正确的 div 中加载内容。不过,我希望它只是加载包含内容片段的部分内容。例如,当有人单击“关于”时,他们会加载部分“应用程序/功能”,这只是一个简单的布局。
<%= link_to "About", {:render => 'application/features'}, :class =>"loader"%>
目前,上面的代码没有加载任何内容,或者 div 中的同一页面。即您加载链接的页面会在目标 div 内重新加载。
这是我的pages.js
$(function(){
$('a.loader').pjax('#pjax')
})
,我的控制器中也有这个
def render(options = nil, extra_options = {}, &block)
if request.headers['X-PJAX'] == 'true'
options = {} if options.nil?
options[:layout] = false
end
super(options,&block)
end
,它会停止渲染布局。
这是我的 div:
<div id="pjax">
</div>
我真正想要实现的只是部分渲染。如果可能的话,可以突出显示链接到的选项卡。即当前选项卡...
I am creating a tab based menu using PJAX in Rails.
I have PJAX working, it loads content in the correct div when I load a normal page. However I would like it just to load partials that contain snippets of content. For example when someone clicks "About" they load the partial "application/features" which is just a simple layout.
<%= link_to "About", {:render => 'application/features'}, :class =>"loader"%>
At the moment the above code loads nothing, Or the same page within the div. I.e. the page you load the link on gets reloaded inside the target div.
This is my pages.js
$(function(){
$('a.loader').pjax('#pjax')
})
I also have this in my controller
def render(options = nil, extra_options = {}, &block)
if request.headers['X-PJAX'] == 'true'
options = {} if options.nil?
options[:layout] = false
end
super(options,&block)
end
which stops the layout being rendered.
this is my div:
<div id="pjax">
</div>
All I really want to achieve is a partial being rendered. And if possible a way of highlighting the tab from which it was linked to. i.e current tab...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
所以,我最终决定不使用 PJAX - 相反,我选择了 Jquery Tools http://flowplayer.org/tools/
我正在寻找的是一个基于选项卡的系统,可以加载部分内容。我通过在 div 中包含一个呈现为选项卡的部分来做到这一点。
So, I decided not to use PJAX in the end - instead i opted for Jquery Tools http://flowplayer.org/tools/
What I was looking for was a tab based system that enabled partials to be loaded. I did this by including a partial in the div that was rendered as the tab.