top button
Flag Notify
    Connect to us
      Site Registration

Site Registration

Having trouble with boolean method in Rails?

+1 vote
374 views

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

view method

Have any ideas to why the method is still showing the button?

posted Feb 8, 2016 by anonymous

Share this question
Facebook Share Button Twitter Share Button LinkedIn Share Button

1 Answer

0 votes
 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.

answer Feb 8, 2016 by Vijay Shukla
Similar Questions
0 votes

What is the best method to manage image uploads in Rails? Is there a tool that allows auto-resizing upon image upload based on predefined dimensions? Moreover, is there any tool available that makes it possible to render / regenerate the same originally uploaded image using alternative view based styles, e.g. thumbs, 320x200 or 640x480 etc..?

+3 votes

In the following code -

 require 'active_record'

 class Order < ActiveRecord::Base
 end

 order = Order.find(1)
 ...

As per http://api.rubyonrails.org/ find() is an instance public method. So why can we call Order.find(1) here? Shouldn't it be Order.new.find(1)?

+2 votes

I have added few libraries in my application and I have tested it in my local machine and they are working. But when I host it on my server and set the env to productions those libraries are not loading or the effects are appearing on my page.

+1 vote

We recently looked at mongoDB a bit. I was discussing using mongoDB with active record but was told that maybe there are other or better options. Can someone comment on that ?

Also, someone suggested storing a ruby array directly inside of a record where I would have opted for the array to be a separate set of records in active record using has_many and belongs_to .. It seemed to me that how I search on those child records would be a big factor but I soon realized I need to find out what are the options. Do people store arrays and hashes directly in mongo DB fields or is that not the best way to go ?

+1 vote

I have a project model which I'd like to set the default_scope to filter out projects where the user doesn't have permission to view them.

Think something along the lines of the projects having a list of teams and companies that the user must be in to access the data.

default_scope seems to work well if I hard code it as I really don't want a dev to accidentally not have these permissions filters in use. The lists of teams and companies a user is in is stored in the session.

...