2016-05-04 10 views
-5

Rails 4.2.6とsqlite3データベースを使用しています。私は、データベースから読み込み可能なファイルにデータを印刷したい。しかし、私が "ショー"ボタンをクリックすると、ショーのルートをPOSTに設定していなくても、このエラーが表示されます。ルーティングエラー[POST] "/ resumes/58"と一致するルートがありません

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 

を教えてください。

+0

多分、ボタンがjsコールシェアの完全なコードを実行していて、 –

+0

のroutes.rbファイルを構成しています。このファイルは、ルーティング作業を行うための中心です。 – JohnPaul

+1

関連するコードを投稿してください。私たちは魔法使いではありません。アプリでエラーが発生するようなコードを表示していないと答えは出せません。 – HashRocket

答えて

0

は、showボタン構文の行を更新してみてください。

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

また、hereはちょっといい異なるHTTPメソッドの記述とその関連Railsのアクションです。

+0

Adrian、私はあなたのソリューションを試しましたが、 "show"ボタンをクリックした後も同じエラーが表示されています –

+0

感謝の気持ちでこのコードは私に違うエラーを与えました...そして、私はインデックスページでform_tagを使用していません'再開'、アクション: 'ショー' ID:resume.id)、メソッド::ショー、 /index.html.erb:28構文エラー、予期しないtIDENTIFIER、期待 ')は' r - エラーが にSyntaxErrorをare-- :構文エラー、予期しないtLABEL 'ショー' ID:resume.id)、メソッド::ショー、クラス:「BTN BTN-プリマ... ^ index.html.erb:28:構文エラー、予期しません ')' 、keyword_end ショーを期待して、クラス:「BTN BTN-主」); =」output_buffer.safe_append @ ... –

+0

は、実は私はこれらのエラーを得た理由のコードにコンマを逃したが、今AGA (アクション: 'show'、id :)はまだそこにありますルーティングエラー ルーターが正しいパスとURLを表示している場合でもルートが[POST]と一致しません –

関連する問題