使提交按钮使用特定路线

时间:2018-04-16 16:28:46

标签: html ruby-on-rails forms

的问题?如何让form.submit按钮使用特定路线?具体来说,用户可以从任何页面填写此表单,它将提交给所需的控制器。

ruby​​ -v 2.3.0 rails 5.0

此表单是一个反馈表单,供用户提交反馈。它的工作方式是,可以点击一个小图标,这样用户就可以从任何页面填写并提交此表单。 问题是,除非用户在主页(本地/客户)上,例如,他们在帖子/ 13上,表单会尝试在示例的顶部添加其URL路由我得到一个"没有路线匹配" ...交/ 13 /客户/问卷调查。

这是我的route.rb

        post 'customers/questionaire' => 'customers#questionaire'

这是表单视图

     <%= form_for :anything, url: "customers/questionaire" ,multiple: 
    true do |form| %>


            <div><%= form.label :email, 'E-mail:' %>
              <%= form.text_field :email , placeholder: 'JohnDoe@yahoo.com' %>

            </div>

            <div><%= form.label :feedback, 'Type of feedback:' %>
              <%= form.text_field :feedback, placeholder: 'Problem, Bug, Idea...' %>
            </div>

            <div><%= form.label :notes, 'Notes: (Required)' %>
              <%= form.text_field :notes, class: 'notes', id: 'notes', placeholder: "Your Feedback" %>
            </div>

            <%= form.submit "Submit", class: "btn1", id: "button", disabled: true %>

      <% end %>

1 个答案:

答案 0 :(得分:1)

我认为你需要这样的东西。做http://localhost:3000/routes。您将获得应用中的所有路线

     <%= form_with scope: :post, url: customers_questionaire_path do |form| %>
        <%= form.text_field :title %>
     <% end %>

对于低轨版本可能是这个:)

<%= form_for :customer, scope: :post, url: customers_questionaire_path  do |form| %>
        <%= form.text_field :title %>
        <%= form.submit %>
     <% end %>
相关问题