2014-11-27 5 views
0

Я использовал rails_admin gem и придумал gem, postgresql для базы данных в моем проекте. После установки Rails admin gem и я увижу localhost: 3000/admin, тогда он выдает ошибку PG :: UndefinedColumn at/ ОШИБКА: column customers.active не существует. Я использовал пользователей и models.I клиентов также создали отношения между двумя models.I думаю, что это проблема ассоциации, но как я могу это исправить я не знаюpostgresql - rails 4 rails_admin column не существует

Вот моя модель пользователя

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

Здесь моя модель клиент

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 

Вот моя конфигурация rails_admin

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 

Вот мой файл маршрут

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) 

грабли БД: обнуление дб: мигрировать --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 

Благодаря вашей помощи!

+0

Вы можете разместить вывод вашей команды Psql «\ d клиентов»? –

+0

Таблица "public.customers" Столбец | Тип --------------- + ----------------------------- ID | integer profile_photo | различный характер (255) full_address | текст user_id | integer created_at | временная метка без часового пояса updated_at | временная метка без часового пояса Индексы: "customers_pkey" PRIMARY KEY, btree (id) "index_customers_on_user_id" btree (user_id) – Karthick

+0

Вы можете добавить его в свой вопрос, вы также можете добавить вывод с помощью '--trace' этих грабли задачи моего ответа. –

ответ

1

Проверьте, была ли выполнена миграция, и если в вашем файле миграции присутствует активный столбец.

Для переделывания ваших миграций использовать:

rake db:reset db:migrate 

EDIT

Теперь я понимаю, ваша проблема, метод active принадлежит user а не customer.

Итак, сначала я думаю, что вы должны взглянуть на this post относительно default_scope. Тогда добиться того, что вы хотите, вы можете использовать метод активный в клиенте, как это:

def active 
    self.user.active 
end 
+0

уже имеет активный столбец в файле схемы – Karthick

+0

@ Karthick по схеме, которую вы подразумеваете в схеме базы данных или в schema.rb? –

+0

в файле schema.rb – Karthick