postgresql - rails 4 rails_admin column does not exist -
i used rails_admin gem , devise gem,postgresql database in project.after installed rails admin gem , going see localhost:3000/admin throws error pg::undefinedcolumn @ / error: column customers.active not exist. have used user , customer models.i created relationship between 2 models.i think association problem how can fix don't know
here user model
class user < activerecord::base has_one :customer, inverse_of: :user accepts_nested_attributes_for :customer, :allow_destroy => true end
here 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 rails_admin configuration
railsadmin.config |config| ### popular gems integration # == devise == config.authenticate_with warden.authenticate! scope: :user end config.current_user_method(&:current_user) config.actions dashboard # mandatory index # mandatory new export bulk_delete show edit delete show_in_app ## audit adapter, can add: # history_index # history_show end end
here route file
rails.application.routes.draw 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: user@example.com ** 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 help!
check if have run migration, , if in migration file there active column.
for redoing migrations use:
rake db:reset db:migrate
edit
now understand problem, active
method belongs user
not customer
.
so first think should take @ this post regarding default_scope
. achieve want may use method active in customer this:
def active self.user.active end
Comments
Post a Comment