0

我在使用 Rails 时遇到问题,我收到以下错误:

No route matches {:action=>"publish", :controller=>"businesses"}

违规代码:

<div id="searchDatesDiv" style="margin: 0 auto;">
  <%= form_tag(publish_business_path, :method => :post) do %>
    <%= submit_tag("Publish") %>
  <% end %>
</div>

路线.rb:

resources :businesses do
  member do
    post 'publish'
  end
end

耙路线:

    registration     GET    /registrations/:id(.:format)         registrations#show
    publish_business POST   /businesses/:id/publish(.:format)    businesses#publish
          businesses GET    /businesses(.:format)                businesses#index
                     POST   /businesses(.:format)                businesses#create

我可以看到 rake 路由中定义的路径。为什么我会收到此错误?该表单也是一种 POST 方法。任何帮助都会很棒!我试过查看关于 SO 的类似问题,但没有找到适合我的问题:(。

4

1 回答 1

0

您的业​​务发布路径需要一个您未提供的 id 参数。因此将业务对象传递给路径助手:

<%= form_tag(publish_business_path(@business), :method => :post) do %>
于 2012-07-30T21:44:03.693 回答