Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

check if user hovers over his status

Hello,

how can I check if I user hover over his status or another user's. I tried couple of different validations, but don't seem to work.

I am trying to remove the edit and delete link if a user is not signed in in the status index page. This works fine. And if a signed in user hovers over another user's status, also I want edit and delete not to appear.

      <% if signed_in? %>
            <span class="admin">
              | <%= link_to "Edit", edit_status_path(status) %> | 
              <%= link_to "Delete", status, method: :delete, data: { confirm: "Delete?"} %>
            </span>
        <% end %>

I tried with additional condition : current_user == @user. But it doesn't work.

Thanks in advance. :)

1 Answer

Personally, I use CanCan : https://github.com/ryanb/cancan It allows you to manage the users ability. In this case, if it's your profile, you'll be easily able to edit | delete your status. It's really easy to install. You should take a look.

Thanks a lot David. :) I will try it out, but I looked at the docs and it looks good.

Also, I saw in the next section of videos some sample code.

<% if signed_in? && current_user == status.user %>

fixed the problem.