N
N
Nazar Jeveling2014-08-03 20:13:52
JavaScript
Nazar Jeveling, 2014-08-03 20:13:52

Problems with routing in Rails?

I have two buttons on the page, one of them deletes Projects, the second one deletes tasks from the Current project.
and eats the routes.rb file :

delete 'todo/index' => 'todo#task_destroy', as: 'destroy_task'
delete 'todo/index' => 'projects#destroy', as: 'destroy_project'

As far as I understand, if the buttons are correctly referenced, then everything should work, but the trouble is, the project deletion button does not work. She uses the first line in routes.rb , thinking she needs to delete the job.
Here is the code for the delete projects button (doesn't work)
<%= link_to image_tag("SVG/trash.svg"), destroy_project_path(project_id: project.id), method: :delete %>

Here is the code for the second button, to delete tasks (works)
<%= link_to image_tag('SVG/minus.svg'), destroy_task_path(task_id: task.id), method: :delete, remote: true %>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kirill Platonov, 2014-08-03
@xo8bit

Routing works fine, there are problems with your code. You are giving the same path for 2 different controllers.
The solution is elementary, as you understand:

delete 'todo/index' => 'todo#task_destroy', as: 'destroy_task'
delete 'projects/index' => 'projects#destroy', as: 'destroy_project'

S
Stanislav Klementiev, 2014-08-03
@Marques

And if you try like this:

<%= link_to image_tag("SVG/trash.svg"), destroy_project_path(project_id: project.id), method: :delete, remote: true %>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question