alex alex - 2 months ago 6
Ruby Question

ruby display delete if product= user product

i have a little problem with a display of a "delete button" i would like that only the user who have post the product can see the button delete so i have try to do a methode who compared id :

def user_publis?
@user=current_user
@publication_id = @publication.user.id
@user_id= @user.id
@publication_id = @user_id
end


a m├ęthode who ask if the publication have build by the current_user

def user_publis?
if @publication=current_user.publications.build
content_tag( :span ,class: "btn btn-rounded") do
content_tag( "my delete button")
end
end


but no one are good....

thx for help and sorry for my english ..^^

Answer

You could just write something like this in your view:

<% if @publication.user == current_user %>
  <span class="btn btn-rounded">
  my delete button...
<% end %>

Or: You can add the following method to your Publication:

def published_by?(user)
  self.user == user
end

and use it in your view like:

<% if @publication.published_by? current_user %>
  <span class="btn btn-rounded">
  my delete button...
<% end %>
Comments