Rails 2.3.8 应用程序跳过控制器
我要问一个有点模糊的问题,但事实是:
我正在维护一个遗留的 Rails 2.3.8 应用程序。我注意到一个奇怪的行为,首先应用程序提供 controller_x/action_x
服务,没有任何错误,因为存在 app/views/controller_x/action_x.rhtml
但没有定义controller_x.rb
中的 action_x
。然后,过了一段时间,它停止服务,我必须在 controller_x.rb
中创建 action_x
空函数,以使其再次服务请求。
什么可能导致这种行为发生?如何在跳过控制器的同时提供操作视图?
更新: 现在出现的错误是:
ArgumentError in ControllerXController#action_x
no id given
谢谢,
I am going to ask a little vague question, but here it goes:
I am maintaining a legacy Rails 2.3.8 application. I noticed a weird behavior, first the application was serving controller_x/action_x
without any errors given that there is an app/views/controller_x/action_x.rhtml
but there is no definition of action_x
in controller_x.rb
. Then, after a while it stopped serving it, I had to create action_x
empty function in controller_x.rb
to make it serve the request again.
What could cause that behavior to happen? How can I serve a view of an action while skipping controller?
Update:
The error occurring now is:
ArgumentError in ControllerXController#action_x
no id given
Thanks,
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
只要定义了相应的视图文件(
action_x.rhtml
),就不必定义操作(定义它是一个很好的做法,这样其他人可以更容易地理解发生了什么在您的项目中)以便提供视图。你遇到什么错误?您的
routes.rb
文件是什么样的?更新:该操作需要一个参数,因此类似这样的内容将起作用:
http://localhost:3000/controller_x/action_x/1
。您确定您的路线文件中只有map.connect ':controller/:action/:id'
吗?As long as you have the corresponding view file defined (
action_x.rhtml
), you don't have to define the action (it's good practice to define it though, so that others can easier understand what's going on in your project) in order for the view to be served.What error are you getting? How does your
routes.rb
file look like?UPDATE: That action is expecting a parameter so something like this will work:
http://localhost:3000/controller_x/action_x/1
. Are you sure you only havemap.connect ':controller/:action/:id'
in your routes file?