0

I used rails_admin gem and devise gem,postgresql for database in my project.After installed that Rails admin gem and i going to see localhost:3000/admin then it throws the error PG::UndefinedColumn at / ERROR: column customers.active does not exist. I have used user and customer models.I also created relationship between their two models.I think this is association problem but how can i fix it i don't know

Here my user model

class User < ActiveRecord::Base
  has_one :customer, inverse_of: :user
  accepts_nested_attributes_for :customer, :allow_destroy => true
end

Here my customer model

class Customer < ActiveRecord::Base
  default_scope { where(active: true).joins(:user).order("user.name") } 
  belongs_to :user, inverse_of: :customer
  validates :user, presence: true
end

Here my rails_admin configuration

RailsAdmin.config do |config|

 ### Popular gems integration

 # == Devise ==
 config.authenticate_with do
  warden.authenticate! scope: :user
 end
 config.current_user_method(&:current_user)

 config.actions do
   dashboard                     # mandatory
   index                         # mandatory
   new
   export
   bulk_delete
   show
   edit
   delete
   show_in_app

   ## With an audit adapter, you can add:
   # history_index
   # history_show
 end

end

Here my route file

Rails.application.routes.draw do
    mount RailsAdmin::Engine => '/admin', as: 'rails_admin'
    resources :customers
    devise_for :users,  :controllers => { omniauth_callbacks: 'omniauth_callbacks' }
end
\d customers
                                   Table "public.customers"
    Column     |            Type             |                       Modifiers                        --------+-----------------------------+-----------------------------------------------
   id          | integer         | not null default nextval('customers_id_seq'::regclass)
   profile_photo | character varying(255)      | 
   full_address  | text                        | 
   user_id       | integer                     | default 1
   created_at    | timestamp without time zone | 
   updated_at    | timestamp without time zone | 
 Indexes:
   "customers_pkey" PRIMARY KEY, btree (id)
   "index_customers_on_user_id" btree (user_id)

rake db:reset db:migrate --trace

 ** Invoke db:reset (first_time)
 ** Invoke environment (first_time)
 ** Execute environment
 ** Invoke db:load_config (first_time)
 ** Execute db:load_config
 ** Execute db:reset
 ** Invoke db:drop (first_time)
 ** Invoke db:load_config 
 ** Execute db:drop
 ** Invoke db:setup (first_time)
 ** Invoke db:schema:load_if_ruby (first_time)
 ** Invoke db:create (first_time)
 ** Invoke db:load_config 
 ** Execute db:create
 ** Invoke environment 
 ** Execute db:schema:load_if_ruby
 ** Invoke db:schema:load (first_time)
 ** Invoke environment 
 ** Invoke db:load_config 
 ** Execute db:schema:load
 -- enable_extension("plpgsql")
    -> 0.0240s
 -- create_table("users", {:force=>true})
     -> 0.1112s
 -- add_index("users", ["active"], {:name=>"index_users_on_active", :using=>:btree})
    -> 0.0549s
 -- add_index("users", ["confirmation_token"],    {:name=>"index_users_on_confirmation_token", :unique=>true, :using=>:btree})
  -> 0.0442s
 -- add_index("users", ["deleted_at"], {:name=>"index_users_on_deleted_at", :using=>:btree})
    -> 0.0442s
  -- add_index("users", ["email"], {:name=>"index_users_on_email", :unique=>true, :using=>:btree})
   -> 0.0442s
  -- add_index("users", ["invitation_token"], {:name=>"index_users_on_invitation_token", :unique=>true, :using=>:btree})
  -> 0.0444s
  -- add_index("users", ["mobile_number"], {:name=>"index_users_on_mobile_number", :using=>:btree})
    -> 0.0440s
  -- add_index("users", ["name"], {:name=>"index_users_on_name", :using=>:btree})
  -> 0.0442s
  -- add_index("users", ["reset_password_token"],  {:name=>"index_users_on_reset_password_token", :unique=>true, :using=>:btree})
   -> 0.0442s
  -- create_table("users_roles", {:id=>false, :force=>true})
    -> 0.0110s
  -- add_index("users_roles", ["user_id", "role_id"], {:name=>"index_users_roles_on_user_id_and_role_id", :using=>:btree})
   -> 0.0332s
  -- create_table("customers", {:force=>true})
     -> 0.0883s
   -- add_index("customers", ["user_id"], {:name=>"index_customers_on_user_id", :using=>:btree})
     -> 0.0442s
  -- initialize_schema_migrations_table()
  -> 0.0666s

   ** Invoke db:structure:load_if_sql (first_time)
   ** Invoke db:create 
   ** Invoke environment 
   ** Execute db:structure:load_if_sql
   ** Invoke db:seed (first_time)
   ** Execute db:seed
   ** Invoke db:abort_if_pending_migrations (first_time)
   ** Invoke environment 
   ** Execute db:abort_if_pending_migrations
   CREATED ADMIN USER: [email protected]
   ** Execute db:setup
   ** Invoke db:migrate (first_time)
   ** Invoke environment 
   ** Invoke db:load_config 
   ** Execute db:migrate
   ** Invoke db:_dump (first_time)
   ** Execute db:_dump
   ** Invoke db:schema:dump (first_time)
   ** Invoke environment 
   ** Invoke db:load_config 
   ** Execute db:schema:dump

Thanks your for help!

3
  • Can you post the ouput of your psql command "\d customers"? Commented Nov 27, 2014 at 11:30
  • Table "public.customers" Column | Type ---------------+----------------------------- id | integer profile_photo | character varying(255) full_address | text user_id | integer created_at | timestamp without time zone updated_at | timestamp without time zone Indexes: "customers_pkey" PRIMARY KEY, btree (id) "index_customers_on_user_id" btree (user_id) Commented Nov 27, 2014 at 11:39
  • You could add it to your question, you can also add the output with '--trace' of those rake tasks of my answer. Commented Nov 27, 2014 at 11:44

1 Answer 1

1

Check if you have run your migration, and if in your migration file there is the active column.

For redoing your migrations use:

rake db:reset db:migrate

EDIT

Now I understand your problem, the active method belongs to the user not the customer.

So first I think you should take a look at this post regarding the default_scope. Then to achieve what you want you may use an method active in customer like this:

def active
  self.user.active
end
Sign up to request clarification or add additional context in comments.

2 Comments

@Karthick by schema you mean in the database schema or in schema.rb?
@Karthick What you have tried? You should also try: default_scope { where(user.active: true).joins(:user).order("user.name") }

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.