In this topic:
Making a table row into a link in Rails I found solution to have a row in table that is a link. But with this solution is little problem. My index.html.haml:
%table.table.table-striped.table-bordered#car_configurations
%thead
%tr
%th{width: "10%"}=t('car_configurations.car_configuration.photo')
%th=t('car_configurations.car_configuration.brand')
%th=t('car_configurations.car_configuration.model')
%th=t('car_configurations.car_configuration.body_style')
%th=t('car_configurations.car_configuration.car_class')
%th=t('car_configurations.car_configuration.cases')
%th
%tbody
- @car_configurations.each do |car_configuration|
%tr{"data-link" => edit_admin_car_configuration_path(car_configuration)}
%td= image_tag car_configuration.image_url(:thumb).to_s
%td= car_configuration.brand.name
%td= car_configuration.model.name
%td= car_configuration.body_style.name
%td= car_configuration.car_class.name
%td= cases(car_configuration)
%td
= link_to ('x'), admin_car_configuration_path(car_configuration), method: :delete, data: {confirm: "Jesteś pewien"}, class: "delete"
= link_to t('car_configurations.index.add'), { action: :new }, class: "btn btn-primary"
In my js.coffee file I have:
$("tr[data-link]").click ->
window.location = @dataset.link
The problem is that when I click my delete link for a moment shows a javascript popoup and then it redirect me to the edit path and I can't delete object. Is there any solution for that?
EDIT:
Thank's for help. Now the destroy link is working but when i click row in table it redirect me to:
http://localhost:3000/admin/undefined
rather than:
http://localhost:3000/admin/car_configuration/1/edit
My index.html.haml looks like this:
%table.table.table-striped.table-bordered#car_configurations
%thead
%tr
%th{width: "10%"}=t('car_configurations.car_configuration.photo')
%th=t('car_configurations.car_configuration.brand')
%th=t('car_configurations.car_configuration.model')
%th=t('car_configurations.car_configuration.body_style')
%th=t('car_configurations.car_configuration.car_class')
%th=t('car_configurations.car_configuration.cases')
%th
%tbody
- @car_configurations.each do |car_configuration|
%tr{"data-link" => edit_admin_car_configuration_path(car_configuration)}
%td= image_tag car_configuration.image_url(:thumb).to_s
%td= car_configuration.brand.name
%td= car_configuration.model.name
%td= car_configuration.body_style.name
%td= car_configuration.car_class.name
%td= cases(car_configuration)
%td{class: "delete"}=link_to ('x'), admin_car_configuration_path(car_configuration), method: :delete, data: {confirm: "Jesteś pewien"}
= link_to t('car_configurations.index.add'), { action: :new }, class: "btn btn-primary"