无法向我的控制器类(RoRails)添加新功能

发布于 2024-08-24 05:02:31 字数 123 浏览 3 评论 0原文

我试图在我的控制器类中定义一个新函数。我使用脚手架制作了所有内容,效果很好。但是现在,当我向控制器添加新功能、设置视图等时,它会显示一些外部错误(当我要求登录时尝试加载显示操作)。

什么脚手架在做我不做的事情? 谢谢

Im trying to define a new function in my Controller class. I made up everything using Scaffolding and it worked okay. But now, when i add a new function to the controller, setting up the view and so, it says some extrange error (tries to load show action when i asked for login).

Whats scaffold doing that im not?
Thanks

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

孤城病女 2024-08-31 05:02:31

您应该在路由文件 (RAILS_APP/config/routes.rb) 中添加一个新条目

如果您有一个 Foo 控制器,

map.resources :foos, :collection => {:bar, :get} # /foos/bar
map.resources :foos, :member => {:foo, :get} # /foos/1/bar

,并且您将添加一个 bar 函数如果这不能解决您的问题,请粘贴您的路由和控制器文件。

You should add a new entry in your routing file (RAILS_APP/config/routes.rb)

if You have for example an Foo controller, and You will ad a bar functon

map.resources :foos, :collection => {:bar, :get} # /foos/bar
map.resources :foos, :member => {:foo, :get} # /foos/1/bar

If this don't solve Your problem, paste Your routing and controller files.

橘香 2024-08-31 05:02:31

脚手架会将 map.resources :controller_name 添加到您的 config/routes 文件中。

此行将为您的控制器生成 7 个静态操作,因此,如果您在控制器中指定任何新操作,它无法识别它,除非您将该操作添加到您的路由中。

如果您想查看应用程序的所有路由操作,您可以运行此 rake 命令

rake paths 它将显示将在您的应用程序中使用的所有路由。

Scaffolding will add map.resources :controller_name to your config/routes file.

This line will generate 7 restful actions for your controller, so if you specify any new action in your controller, it can't recognize it unless you add the action to your routes.

If you want to see all the route actions for you app you can run this rake command

rake routes it will show all the routes that will be used in your application.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文