dimanche 10 décembre 2017

how to access column using devise user

I added the following columns using a new migration as follows:

class AddDetailsToUser < ActiveRecord::Migration
  def change
    add_column :users, :userNum, :integer
    add_column :users, :username, :string
    add_column :users, :fname, :string
    add_column :users, :surname, :string
    add_column :users, :isTeacher, :boolean, :default => false


  end
end

Now in the application.html.erb I want to do something like this which is trying to show button only when the user is actually a teacher :

<% if @user.isTeacher? %>
                    <div class="buttons">
                        <%= button_to(etc ..) %>
                    </div>
<% end %>

but the problem is that I get the following error message:

undefined method `isTeacher?' for nil:NilClass

How to fix this problem ?

Thanks for your time

Aucun commentaire:

Enregistrer un commentaire