简体   繁体   English

在Ruby on Rails中,如何将控制器中的所有动作映射到root?

[英]In Ruby on Rails, how can I map all actions in a controller to root?

In Ruby on Rails, how can I do the equivalent of this in a more elegant routes line? 在Ruby on Rails中,如何在更优美的路线中做到这一点? I may have to add many of these... 我可能不得不添加许多...

  map.connect '/about', :controller => "site", :action => "about"
  map.connect '/contact', :controller => "site", :action => "contact"
  map.connect '/preview', :controller => "site", :action => "preview"

Thanks! 谢谢!

You can do this: 你可以这样做:

map.connect '/:action', :controller => "site", :action => /about|contact|preview/

The part :action => /about|contact|preview/ makes sure that only the listed words can be used as action in this route,. :action => /about|contact|preview/可确保仅列出的单词可以在此路线中用作action

但是不要忘了将@Tomas建议的路由移动到您的route.rb的底部,否则它将捕获不应捕获的路由。

暂无
暂无

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

相关问题 如何在Ruby on Rails中从控制器映射数据 - How can i map the data from controller in Ruby on Rails 如何将控制器的所有操作映射到Rails的顶层? - How do I map all actions for a controller to the top-level in Rails? Ruby on Rails:devise:,我如何允许帖子/索引和帖子/显示操作对所有操作,但其他操作将被拒绝 - Ruby on rails: devise :, how can i allow posts/index and posts/show action to all but other actions will be denied 如何在Ruby on Rails中生成控制器动作数组? - How to generate an array of controller actions in Ruby on Rails? 传统上如何将控制器动作映射到导轨中的路由? - How to conventionally map controller actions to routes in rails? 向控制器Ruby on Rails中的所有相关动作添加活动类 - Add active class to all relative actions inside controller Ruby on Rails 如何将Rails应用程序的根路由到特定控制器? - How can I route the root of a Rails app to a specific controller? Ruby on rails - 如何使控制器与ajax同时执行2个动作? - Ruby on rails - How to make controller execute 2 actions simultaneously with ajax? 如何在Rails的ruby中的单个页面选项卡中调用多个控制器动作 - How to call multiple controller actions into the single page tabs in ruby on rails Rails模型是一个普通的ruby类,可用于在不同的控制器操作之间存储状态吗? 根本没有活动记录和无数据库 - Is a Rails Model a normal ruby class that can be used to store state between different controller actions? No active-record and no-database at all
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM