Abstractcontroller::Actionnotfound for the Destroy action

Asked

Viewed 93 times

0

Hello,

I have two applications running on Heroku with the same code, only I’m having a little problem with the producing.

When trying to make a request, I have the following log:

AbstractController::ActionNotFound (The action 'destroy' could not be found for Managers::RecruitmentsController)

The problem is that it is trying to search in the controller Managers::RecruitmentsController, but the correct would be in Managers::ApplicantsController, as already happens in the version dev:

Started DELETE "/managers/recruitments/1/applicants/7" for 179.156.49.112 at
Processing by Managers::ApplicantsController#destroy as HTML

Well, this request comes from link_to down below:

 <%= link_to "Outra chance?", "javascript:;", id: "newChance", method: 'delete', btn: true, style: :link, 'data-toggle' => 'modal', 'data-target' => '#modalNewChance', 'data-applicant-id' => applicant.id %>

Javascript:

 <script language="javascript">
   $("#newChance").on('click', function() {
       $("#linkNewChance").attr('href', '/managers/recruitments/<%=  @recruitment.id %>/applicants/' + $("#newChance").data('applicant-id'));
       });
 </script>

My controller:

class Managers::ApplicantsController < Managers::BaseController
...
def destroy
  @applicant = Applicant.find(params[:id])

  CandidatesMailer.new_chance(@applicant).deliver
  CompanyMailer.new_chance_company(@applicant).deliver

  @applicant.destroy

  flash[:success] = "Aplicação resetada com sucesso. Candidato tem nova chance."
  redirect_to managers_recruitment_path(params[:recruitment_id])
end

My routes:

namespace :managers do
 get "guide/index"
 resource :dashboard, only: :show
 resource :profile,   only: [:show, :edit, :update]
 resource :company,   only: [:edit, :update, :destroy] do
   resource :payment, only: [:edit, :update]
 end
 resources :plans,    only: [:new, :create], path_names: { new: 'choose' }
 resources :recruitments do
  member do
    patch 'close'
  end
  resources :applicants do
    member do
      put 'comment'
      patch 'comment'
    end
  end
 end
end

Here are the Routes related to the mentioned controllers.

  • 1

    what appears when you rotate a rake Routes?

  • @Thiagodiniz,appears all routes, but as for the controller in question I will edit in my reply.

  • You checked if the route is right in html?

  • Wow @Thiagodiniz... I didn’t think about it! I refactored the code by transferring the link_to for a view to respond to the same controller that in the case was Applicants. Like, the view I was making the request was related to the Recruitments controller, so I transferred the code to the view that responds to the Applicants controller, without losing value to the business. I don’t know if this was the problem but it worked out. PS.: I’m a beginner in the Rails world!

1 answer

1

the end-point that is called in the code snippet

<script language="javascript">
  $("#newChance").on('click', function() {
  $("#linkNewChance").attr('href', '/managers/recruitments/<%=  @recruitment.id %>/applicants/' + $("#newChance").data('applicant-id'));
  });
 </script>

Take it to the controller Managers::RecruitmentsController same... Rails is doing right, as can be observed on line 26 of the exit routes you posted

https://gist.github.com/augustoppimenta/afe3cb6163f2e9cf13#file-Routes-L26

there is no redirect occurring before the Rails router processes your URL?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.