Editor Role 1 exercise 1 another bug!

Got another bug halting my progress here in Editor Role 1 exercise 1. Instructions:

Let’s add a method to the User model that will help us use the role column in our application. Within the class User, beneath the has_secure_password method, type:

def editor?
self.role == ‘editor’
end

Here is my code:
‘’’
class User < ActiveRecord::Base
has_secure_password
def editor?
self.role == ‘editor’
end
end
‘’’

There are no typos. This is fairly straight forward. Why am I getting an error, “/var/lib/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:512:in `table_structure’: Could not find table ‘users’ (ActiveRecord::StatementInvalid)?” The error indicates Rails is having issues with the table “users” that was in the db/migrate file in the last step. I can’t find anything wrong with the code.

Hi Drew,

First - Thanks for trying to format your code, but there’s something which confuses a lot of people that you need to remember: backticks aren’t the same as single quotes. Look:

' single quote
` backtick

See how the backtick “tilts”?


/var/lib/gems/2.0.0/gems/activerecord-4.1.1/lib/active_record/connection_adapters/sqlite3_adapter.rb:512:in `table_structure’: Could not find table ‘users’ (ActiveRecord::StatementInvalid)?

Have you run rake db:migrate in the terminal yet?

Thanks for your replies zystvan! I feel so stupid that I couldn’t find the backtick on the keyboard until now!

Yes, when I read the error message I went back and checked my migration and ran the rake. Tried that 3x and I still got that same error.

For whatever the reason, Rails didn’t like my spacing and indentation on that code. Once I added some more spaces and indents, it ran and let me pass. I had to get the solution code from codeacademy to figure that out though.

class User < ActiveRecord::Base
has_secure_password
def editor?
 self.role == 'editor'
end
end
1 Like

Haha, that’s fine. It’s not like it’s a very commonly used key, anyway :smile:

That’s strange - it shouldn’t be depending on whitespace to (not) pass you :confused:
I’ll see if I can take a look at this later and maybe figure out what’s wrong here :slight_smile: