如何在创建url时让url helper忽略控制器名称?

时间:2017-10-26 22:42:14

标签: ruby-on-rails

我在Rails部分中使用form_for。这是一个Rails 4应用程序。评论对象是多态belongs_to :document。文档可以是ContactService对象,也可能是未来的其他内容:

<%= form_for [document, Comment.new], remote: true, html: { class: "form-responsive", data: { confirm: 'Confirm' } } do |f| %>
    ...
<% end %>

当文档是联系人对象时,我希望它生成url帮助器contact_comments_path。它确实如此,直到Rails源代码中的这一点:

class HelperMethodBuilder
   def self.polymorphic_method(recipient, record_or_hash_or_array, action, type, options)
     if options.empty?
       recipient.send(method, *args)

method是字符串contact_comments_path。但调用此方法的结果是fullcalendar_engine_contact_comments_path。控制器名称以我想要的URL为前缀

这是因为此表单位于与fullcalendar_engine索引操作对应的视图中。我该如何解决这个问题?

1 个答案:

答案 0 :(得分:0)

form_for接受一个网址选项,您可以在其中指定要用于表单操作的路径。

相关问题