ruby on rails 中的导航栏,产量 - IT屋-程序员软件开发技术分享社区
首页
其他开发
ruby on rails 中的导航栏,产量
ruby on rails 中的导航栏,产量
[英] navbar in ruby on rails with yield
本文介绍了ruby on rails 中的导航栏,产量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
因此,在浏览各种论坛、教程等几天之后 - 我仍然没有接近做一些看似简单的事情 - 即,在导航栏上有链接,用部分内容填充命名产量.我可能缺少一些基本的东西,但是嘿!我之前问过这个问题,但我觉得我的问题不太好,所以希望这次我会做得更好!
我的观点:
<html lang="zh-cn"><头><meta charset="utf-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1"><meta name="description" content=""><meta name="author" content=""><link rel="快捷图标" href="../../assets/ico/favicon.ico"><title>软件开发工具网络用户界面</title>头部><div class="容器"><!-- 静态导航栏--><div class="navbar navbar-default" role="navigation"><div class="container-fluid"><div class="navbar-header"><button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">按钮><a class="navbar-brand" href="#">MARS Web UI</a>
<div class="navbar-collapse collapse"><ul class="nav navbar-nav">XXXXXXXXX<ul class="nav navbar-nav navbar-right"><li class="active"><a href="./">注销</a></li></div><!--/.nav-collapse --></div><!--/.container-fluid -->
<身体><div class="容器"><%=产率:主体%>
<脚本>$(".nav li").on("click", function() {$(".nav li").removeClass("active");$(this).addClass("active");});</html>
在上面插入XXXXXXX的地方,我试过了:
<li><a href="<%= content_for :mainbody do; render 'authentication/perforce'; end %>">P4</a></li><li><a href="<%= content_for :mainbody do; render 'authentication/p4_output'; end %>">P4 Output</a></li>
这只是将perforce"和p4_output"部分渲染到另一个下面,并且单击导航栏选项没有效果.
所以我想可能需要更像这样的东西:
<%= link_to "Perforce", {:action =>'renderp4'}, :remote =>真%>/li><li class="active"><%= link_to "Perforce", {:action =>'renderp4_output'}, :remote =>真%>/li>
但在这一点上,我停下来了,不知道在我的renderp4"和renderp4_output"操作中需要什么才能将 HTML 返回到我的主体产量 - 如果它甚至可能?!?
希望我想要实现的目标是显而易见的 - 虽然我很欣赏并承认我目前的解决方案可能相当广泛,但任何指导都将不胜感激.正如我所说,我四处打猎,但只是撞到了一堵砖墙!
谢谢:)
解决方案
创建renderp4.js.erb文件
$('.container').replaceWith('<%= escape_javascript render "authentication/perforce" %>');
So after a couple of days of trawling various forums, tutorials etc - I'm still no closer to doing what is seemingly something straightforward - namely, have links on a Navbar populate a named yield with the contents of a partial. I'm probably missing something fundamental, but hey! I've asked this before, but I don't think I worded the question too well, so hopefully this time I'll do better!
My view:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="">
<meta name="author" content="">
<link rel="shortcut icon" href="../../assets/ico/favicon.ico">
<title>Software Dev Tools Web UI</title>
</head>
<div class="container">
<!-- Static navbar -->
<div class="navbar navbar-default" role="navigation">
<div class="container-fluid">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
</button>
<a class="navbar-brand" href="#">MARS Web UI</a>
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
XXXXXXXXX
</ul>
<ul class="nav navbar-nav navbar-right">
<li class="active"><a href="./">Logout</a></li>
</ul>
</div><!--/.nav-collapse -->
</div><!--/.container-fluid -->
</div>
</div>
<body>
<div class="container">
<%= yield :mainbody %>
</div>
</body>
<script>
$(".nav li").on("click", function() {
$(".nav li").removeClass("active");
$(this).addClass("active");
});
</script>
</html>
Where I have inserted XXXXXXX above, I have tried:
<li><a href="<%= content_for :mainbody do; render 'authentication/perforce'; end %>">P4</a></li>
<li><a href="<%= content_for :mainbody do; render 'authentication/p4_output'; end %>">P4 Output</a></li>
This simply rendered both "perforce" and "p4_output" partials one below the other, and clicking the navbar options had no effect.
So then I figured maybe something more like this was required:
<li class="active"><%= link_to "Perforce", {:action => 'renderp4'}, :remote => true %></li>
<li class="active"><%= link_to "Perforce", {:action => 'renderp4_output'}, :remote => true %></li>
But at this point I came to a grinding halt, not knowing how what would be needed in my "renderp4" and "renderp4_output" actions so as to return HTML to my mainbody yield - if it is even possible?!?
Hopefully what I am trying to achieve is obvious - while I appreciate and acknowledge I am probably rather wide of the mark with my solution currently, any guidance would be appreciated. As I say, I've hunted around, but just hit a brick wall!
Thanks :)
解决方案
Create a renderp4.js.erb file
$('.container').replaceWith('<%= escape_javascript render "authentication/perforce" %>');
这篇关于ruby on rails 中的导航栏,产量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文