-5

I'm using Rails 4.2.6 with an sqlite3 database. I want to print the data from database into a file which is readable. But when I click the "Show" button it gives me this error even though I haven't set show's route to POST.

Here is the stuff am working with:

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 routes:

         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

Please tell me if anything else is also needed.

atw
  • 5,428
  • 10
  • 39
  • 63

1 Answers1

0

Try updating the show button syntax line:

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

Also, here is a nice little description of the different HTTP method and their related Rails actions.

Community
  • 1
  • 1
atw
  • 5,428
  • 10
  • 39
  • 63
  • Adrian, I tried your solution but it's still showing that same error after clicking "show" button – Aarzoo Goyal May 04 '16 at 10:40
  • Thankx for that update but this code gave me different errors...And please notice I am not using any form_tag in my index page..The errors are-- SyntaxError - syntax error, unexpected tIDENTIFIER, expecting ')' r: 'resumes', action: 'show' id: resume.id), method: :show, /index.html.erb:28: syntax error, unexpected tLABEL 'show' id: resume.id), method: :show, class: "btn btn-prima... ^ index.html.erb:28: syntax error, unexpected ')', expecting keyword_end show, class: "btn btn-primary");@output_buffer.safe_append='... – Aarzoo Goyal May 04 '16 at 11:45
  • Actually you missed a comma in the code that's why I got those errors but now again after adding a comma (action: 'show', id:) am still there Routing Error No route matches [POST] even when the router is showing the correct paths and urls – Aarzoo Goyal May 04 '16 at 12:01
  • I made another edit(including missing comma), note, `method: :get` instead of `method: :show`. `show` is the name of the method. However, `show` is a `get` request. – atw May 04 '16 at 12:45
  • yup...but I used :show at that place.. and still the same – Aarzoo Goyal May 04 '16 at 12:58
  • Hey, the above code is correct. We have to use method: :get instead of using "show" as we have passed the action inside url_for() Thankx @Adrian Mann :) – Aarzoo Goyal May 05 '16 at 06:24