Rails 3:在索引页上使用 POST 表单?
在我的 Rails 3.0 应用程序中,我的资源:索引页面上有一系列非常大的搜索表单,需要使用 POST 而不是 GET。
目前,当我希望应用程序路由到resource#index 时,该应用程序正在将POST 请求路由到resource#create。我意识到这是 RESTful 路线,但需要覆盖它。我怎样才能做到这一点,同时又保留创建该资源的新记录的能力?
非常感谢。
In my Rails 3.0 app I have a series of very large search forms on my resource:index page, requiring the use of POST instead of GET.
Currently, the app is routing the POST request to resource#create, when I want it to route to resource#index. I realize this is the RESTful route, but need to override it. How can I do that, while also preserving the ability to create a new record of that resource?
Thanks much.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您最好进行仅发布的“搜索”操作,然后呈现索引模板,例如:
You're better off having a "search" action that is post-only - and then renders the index template eg:
您可以使用索引,只需将其添加到 Rails 3 路由中:
You can use index, just add this in Rails 3 routes:
那么您希望控制器中的“创建”操作端点执行两件事 - 响应搜索并执行创建?坏主意,但解决方案可能就像在创建操作中使用“if”条件来执行其中一项操作一样简单。如果答案不令人满意,请随时进一步澄清您的问题。
So you want your "create" action end-point in the controller to do 2 things - Respond to search and do the create also? Bad idea, but the solution might be as simple as using an "if" condition in the create action to do one or the other. If its not a satisfactory answer, feel free to clarify your question a bit more.