简体   繁体   English

Ruby on Rails中的下拉菜单

[英]Drop down menu in Ruby on Rails

%p{style: "float: right;"}
= link_to "Report", blog_post, method: :Report, confirm: 'Why do you want to report?'

How to use a drop down menu if I want to have a pop up containing "Why do you want to report?" 如果我想弹出一个包含“为什么要举报?”的下拉菜单,该如何使用下拉菜单。 and a drop down menu containing the reasons under the question? 以及包含问题下原因的下拉菜单?

您应该添加jquery-rails: https : //github.com/indirect/jquery-rails也可以按照以下教程进行操作: http : //joshhuckabee.com/jquery-rails-3

You may use twitter bootstrap drop down menus. 您可以使用twitter bootstrap下拉菜单。 http://twitter.github.com/bootstrap/javascript.html http://twitter.github.com/bootstrap/javascript.html

Download the bootstrap-dropdown.js file and put it your assets file. 下载bootstrap-dropdown.js文件并将其放入资产文件。 Call dropdown by $('.dropdown-toggle').dropdown() 通过$('。dropdown-toggle')。dropdown()进行呼叫下拉

There is also a demo about how to use that. 还有一个有关如何使用它的演示。

In Rails view template, you need simply write iteration over menu-elements: 在Rails视图模板中,您只需在菜单元素上编写迭代即可:

<ul class="dropdown-menu">
  <% @menu_items.each do |item| %>
    <li><a href="#"><%= item.title %></a></li>
  <% end %>
</ul>

then you need to add a little css/javascript magic to make this list looks like drop-down menu. 那么您需要添加一点CSS / JavaScript魔术,以使该列表看起来像下拉菜单。 There's a plenty of tutorials about that topic, but much easier way, as was noted above, is simply to use twitter-bootstrap. 关于该主题有很多教程,但是如上所述,更简单的方法就是使用twitter-bootstrap。 http://twitter.github.com/bootstrap/javascript.html#dropdowns . http://twitter.github.com/bootstrap/javascript.html#dropdowns (you may check this gem to include twitter-bootstrap into your rails app) (您可以检查此gem,以将twitter-bootstrap包含在rails应用程序中)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM