【问题标题】:Routing Error No route matches [POST] "/resumes/58"路由错误没有路由匹配 [POST] "/resumes/58"
【发布时间】:2016-05-04 07:03:57
【问题描述】:

我正在使用带有 sqlite3 数据库的 Rails 4.2.6。我想将数据库中的数据打印到可读的文件中。但是当我单击“显示”按钮时,即使我没有将显示的路由设置为 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

rake 路线:

         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

如果还需要什么,请告诉我。

【问题讨论】:

  • 可能按钮正在触发 js 调用共享完整代码和路由
  • 在 routes.rb 文件中配置东西——这个文件是使路由工作的核心
  • 请贴上相关代码。我们不是魔术师。如果您不向我们展示一些导致您的应用出错的代码,我们将无法给您答复。

标签: ruby-on-rails-4


【解决方案1】:

尝试更新显示按钮语法行:

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

另外,here 是对不同 HTTP 方法及其相关 Rails 操作的简短描述。

【讨论】:

  • 阿德里安,我尝试了您的解决方案,但单击“显示”按钮后仍然显示相同的错误
  • 感谢更新,但这段代码给了我不同的错误......请注意我没有在我的索引页面中使用任何 form_tag..错误是-- SyntaxError - 语法错误,意外的 tIDENTIFIER,期待 ')' r: 'resumes', action: 'show' id: resume.id), method: :show, /index.html.erb:28: 语法错误,意外 tLABEL 'show' id: resume.id) ,方法::show,类:“btn btn-prima ... ^ index.html.erb:28:语法错误,意外')',期待keyword_end显示,类:“btn btn-primary”);@output_buffer。 safe_append='...
  • 实际上你在代码中遗漏了一个逗号,这就是我得到这些错误的原因,但现在又在添加逗号后(操作:'show',id :) 仍然存在路由错误没有路由匹配 [POST]即使路由器显示正确的路径和网址
  • 我做了另一个编辑(包括缺少逗号),注意,method: :get 而不是method: :showshow 是方法的名称。但是,showget 请求。
  • 是的...但我在那个地方使用了 :show .. 还是一样
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-09-27
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多