0

我理解路线的概念,但有时它们不能正常工作。在这种特定情况下,我试图让编辑项目的路线工作,但我收到以下错误消息:

No route matches [POST] "/projects/8/edit"

路线.rb:

Ampta::Application.routes.draw do
  get "home/index"

  resources :sessions, only: [:new, :create, :destroy]

  match '/signin',  to: 'sessions#new'
  match '/signout', to: 'sessions#destroy', via: :delete

  resources :projects do
    collection do
      get "manage" 
    end 
  end

  resources :projects
  resources :tickets
  resources :projects_users
  resources :users

  root :to => 'home#index'

end

控制器:

class ProjectsController < ApplicationController
    def edit
        // no code yet
    end
end

看法:

<% @users_projects.each do |project| %>
    <%= link_to project.title, project_path(project), :class => "manage_project_link" %>
    <%= button_to "Edit", edit_project_path(project), :class => "btn edit_button" %>
<% end %>

怎么了?运行rake 路由时要找到该路由

 edit_project GET    /projects/:id/edit(.:format)       projects#edit
4

1 回答 1

3

更仔细地查看错误消息:

No route matches [POST] "/projects/8/edit"

它实际上是使用动词POST而不是GET。这就是它找不到路径的原因。

您正在使用生成表单的button_to助手,默认方法是POST.

您只需要更改button_tolink_to.

于 2013-02-11T18:31:56.837 回答