在某些情况下未使用命名路由? - AbstractController::ActionNotFound
我有一个使用 jQuery 自动完成功能返回客户名称列表的表单。对于自动完成功能,源设置为命名路由。
$( "#clientfinder" ).autocomplete({
source: 'findclients',
minLength: 3,
delay: 600,
select: function(event,ui){
$('#clientfinder_id').val(ui.item.id)
}
});
-- routes
match 'findclients' => 'contact#find_clients'
只要表单字段用于更新记录而不是创建新记录,使用路由的自动完成源就可以正常工作。创建和更新视图都使用相同的部分 _form.html.erb,因此相同的字段具有相同的 id。但是当使用表单创建记录时,我得到:
Started GET "/search_log/findclients?term=fid" for 127.0.0.1 at 2011-10-07 11:45:59 -0500 AbstractController::ActionNotFound(无法为 SearchLogController 找到操作“findclients”):
创建记录后,我使用表单更新记录,我得到:
Started GET "/findclients?term=fid" for 127.0.0.1 0.1 于 2011-10-07 11:46:56 -0500 通过 ContactController#find_clients 作为 JSON 进行处理
就像使用表单部分进行创建一样,指定的路由将被忽略并调用当前的控制器。但如果表单用于更新记录,则使用命名路由。我不明白 Rails 框架如何知道其中的区别。
我在这里错过了什么吗?
I have a form that uses jQuery autocomplete to return a list of client names. For the autocomplete function the source is set to a named route.
$( "#clientfinder" ).autocomplete({
source: 'findclients',
minLength: 3,
delay: 600,
select: function(event,ui){
$('#clientfinder_id').val(ui.item.id)
}
});
-- routes
match 'findclients' => 'contact#find_clients'
The autocomplete source using the route works fine as long as the form field is used for updating a record, but not for creating a new record. The create and update views both use the same partial _form.html.erb, and therefore the same field with the same id. But when the form is used to create a record I get:
Started GET "/search_log/findclients?term=fid" for 127.0.0.1 at 2011-10-07 11:45:59 -0500
AbstractController::ActionNotFound (The action 'findclients' could not be found for SearchLogController):
Once the record is created and I'm using the form for updating the record I get:
Started GET "/findclients?term=fid" for 127.0.0.1 at 2011-10-07 11:46:56 -0500
Processing by ContactController#find_clients as JSON
It's like if the form partial is use for creation, the named route is ignored and the current controller is called. But if the form is used for updating a record, the named route is used. I don't see how the rails framework knows the difference.
Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论