如何在 Rails 3 中为以下代码创建下拉菜单?
考虑一个 HTML 链接列表:
<a href="/d_population/1">User 1 name link</a><br>
<a href="/d_population/2">User 2 name link</a><br>
此代码生成列表:
<% User.all.each do |user| %>
<%= link_to user.name + " link", d_population_path(user.id) %><br>
<% end %>
相关路由是:
match 'd_population/:this_client', :to => 'dashboard#population', :as => 'd_population'
我想使用 HTML 下拉列表来发出相同的 HTTP 请求。
是否可以使用下拉列表发出类似于 /d_population/1
的 HTTP 请求?
我尝试使用 form_tag
和 select_tag
生成下拉列表并将 this_client
作为参数传递,但不断收到路由错误。您是否需要添加路由 d_population/
才能使下拉菜单正常工作?
谢谢。
Consider an HTML list of links:
<a href="/d_population/1">User 1 name link</a><br>
<a href="/d_population/2">User 2 name link</a><br>
This code generates the list:
<% User.all.each do |user| %>
<%= link_to user.name + " link", d_population_path(user.id) %><br>
<% end %>
The relevant route is:
match 'd_population/:this_client', :to => 'dashboard#population', :as => 'd_population'
I would like to use an HTML dropdown to make the same HTTP request.
Is it possible to use a dropdown to make a HTTP request that looks like /d_population/1
?
I attempted to use form_tag
and select_tag
to generate the dropdown and pass this_client
as a parameter, but kept getting routing errors. Do you need to add a route d_population/
to make a dropdown work?
Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这里有一些资源可以帮助您开始使用下拉菜单和菜单选项
卡 on Rails 是一个很棒的 Gem,它将帮助您在 Rails 中生成 Li 菜单 http://www.simonecarletti.com/code/tabs_on_rails/
Bootstrap 是一个 UI 框架,由 Twitter 开发 http://twitter.github.com/bootstrap/
我已经在当前项目中成功实现了这两个功能我一直在努力。
here are a few resources to help you get started with Dropdowns and Menu's
Tabs on Rails is an awesome Gem that will help you generate Li menu's in Rails http://www.simonecarletti.com/code/tabs_on_rails/
Bootstrap is a UI Framework, developed by Twitter http://twitter.github.com/bootstrap/
I've successfully implemented both of these in a current project that i've been working on.