路由错误没有路由匹配[POST]" / resume / 58"

时间:2016-05-04 07:03:58

标签: ruby-on-rails-4

我使用Rails 4.2.6和sqlite3数据库。我想将数据库中的数据打印到可读的文件中。但是当我点击" Show"按钮它给了我这个错误,即使我没有设置show的路线到POST。

以下是我正在使用的内容:

index.html.erb:

<% if !flash[:notice].blank?%>
   <div class="alert alert-info">
    <%= flash[:notice]%>

   </div>
<%end%>
<br />

<%= link_to "New File", new_resume_path, class: "btn btn-primary"%>
<br />
<br />

<table class="table table-bordered table-striped">
    <thead>
        <tr>
            <th>Name</th>
            <th>Download Link</th>
            <th></th>
        </tr>   
    </thead>
    <tbody>
        <% @resumes.each do|resume| %>
        <tr>
            <td><%= resume.name%></td>
            <td><%= link_to "Download Resume", resume.attachment_url %></td>
            <td><%= button_to "Delete", resume, method: :delete, class: "btn btn-danger", confirm: "Are you sure to delete #{resume.name}?" %></td>
            <td><%= button_to "Show", resume, method: :show, class: "btn btn-primary"%></td>        
        </tr>

      <% end %>
    </tbody>

</table>

routes.rb中:

Rails.application.routes.draw do


   resources :resumes 
   root "resumes#index"

  get 'resumes/index'

  get 'resumes/new'

  get 'resumes/create'

  get 'resumes/destroy'

  get 'resumes/show'
end

佣金路线:

         Prefix Verb   URI Pattern                 Controller#Action
        resumes GET    /resumes(.:format)          resumes#index
                POST   /resumes(.:format)          resumes#create
     new_resume GET    /resumes/new(.:format)      resumes#new
    edit_resume GET    /resumes/:id/edit(.:format) resumes#edit
         resume GET    /resumes/:id(.:format)      resumes#show
                PATCH  /resumes/:id(.:format)      resumes#update
                PUT    /resumes/:id(.:format)      resumes#update
                DELETE /resumes/:id(.:format)      resumes#destroy
           root GET    /                           resumes#index
  resumes_index GET    /resumes/index(.:format)    resumes#index
    resumes_new GET    /resumes/new(.:format)      resumes#new
 resumes_create GET    /resumes/create(.:format)   resumes#create
resumes_destroy GET    /resumes/destroy(.:format)  resumes#destroy
   resumes_show GET    /resumes/show(.:format)     resumes#show

如果还需要其他任何内容,请告诉我。

1 个答案:

答案 0 :(得分:0)

尝试更新show button语法行:

<td><%= button_to "Show", url_for(controller: 'resumes', action: 'show', id: resume.id), method: :get, class: "btn btn-primary"%></td>

此外,here是对不同HTTP方法及其相关Rails操作的一个很好的描述。