How do I create DESTROY link with Slim?

Asked

Viewed 101 times

0

I’m starting with Rails, and I’m not able to link to delete a "post" from the site.

Follows how the links are new and edit

p.btn = link_to "Editar informações", edit_property_path(@property) if current_user == @property.user

p.btn = link_to "Editar imagens", new_property_media_content_path(@property) if current_user == @property.user

p.btn = link_to "Excluir
", property_path(@property) if current_user == @property.user, :confirm => 'Are you sure?', :method => :delete

Shows the error:

syntax error, Unexpected ',', expecting ')'

  • Good Morning! You could show the entire code of your index.html.slim

1 answer

0


Buenas, is wrong the way you are using the check inside the link Excluir. Vale recalls that the link_to is a method so what you send to it are the parameters, should not put the check there to show or not the link.

Follow your refactored example: if current_user == @property.user p.btn= link_to "Editar informações", edit_property_path(@property) p.btn= link_to "Editar imagens", new_property_media_content_path(@property) p.btn= link_to 'Excluir', property_path(@property), :method => :delete, :data => {:confirm => 'Are you sure?'}

  • Hello Jean, thank you for the answer!! I ended up solving with "= link_to "Delete", property_path, method: :delete, date: {confirm: 'Are you sure you want to delete this property? '} if current_user == @Property.user" See that without "(@Property)". So the if current_user check == @Property.user works and the link only appears to the user who posted the immovable.. Hug

Browser other questions tagged

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