Ruby on Rails Sunday, February 7, 2016

> On Feb 7, 2016, at 7:20 PM, David Williams <lists@ruby-forum.com> wrote:
>
> I'm checking if a user is an admin, and then I will show a delete button
> if he is. For whatever reason, it's automatically setting the boolean to
> true. It says is_admin: false in the console when I pull up the user's
> record.
>
>
> Check status of user
> def is_admin?
> self.username
> end

This method is going to return the username, which is probably set to something, and that means true when you ask this way. You probably meant to check if the admin attribute on that user model.

Walter

>
>
> view method
> <% if @user.is_admin? %>
> <%= link to 'Delete', remove_bla_bla_path(user), method: :destroy %>
> <% end %>
>
> Have any ideas to why the method is still showing the button?
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/e271d6cdea52f5ca85bb048cb9f21afd%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/73152A51-1224-4FFE-B089-377A344FBFA0%40wdstudio.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment