기본적으로 양식을 통해 db 테이블과 상호 작용하는 웹 응용 프로그램에서 작업하고 있습니다. 최근에 나는 db 테이블에 다른 컬럼을 추가하는 몇 가지 변경 사항을 만들어야했습니다. 개발을 위해 RubyMine을 사용하고 있으며 모델을 업데이트하여 새로운 열이 포함되도록하는 방법을 알 수 없습니다.RubyMine을 사용하여 모델에서 열 추가/업데이트
class Student < ActiveRecord::Base
attr_accessible :f_name, :floor_pref, :l_name, :is_active
validates_presence_of :f_name, :floor_pref, :l_name
end
나는 또한 schema.rb 내부를 추가했습니다 :
ActiveRecord::Schema.define(:version => 20130620140537) do
create_table "students", :force => true do |t|
t.string "f_name"
t.string "l_name"
t.string "floor_pref"
t.boolean "is_active"
t.datetime "created_at", :null => false
t.datetime "updated_at", :null => false
end
end
그리고 또한 그렇게 마이그레이션 내부 :
class CreateStudents < ActiveRecord::Migration
def change
create_table :students do |t|
t.string :f_name
t.string :l_name
t.string :floor_pref
t.boolean :is_active
t.timestamps
end
end
end
나는 그래서 모델의 내부를 추가했습니다
레일즈 콘솔을 실행하고 모델 객체를 검색 할 때 내가 추가 한 새 컬럼 (: is_active)이 표시되지 않는 경우가 있습니다. 이전 열만 표시 :
>> Student
Loading development environment (Rails 3.2.13)
Switch to inspect mode.
Student(id: integer, f_name: string, l_name: string, floor_pref: string, created_at: datetime, updated_at: datetime)
무엇이 누락 되었습니까?
첫 번째 명령의 경우 정확한 구문을 사용해야합니까, 아니면 변경해야합니까? – Nick
아니요 당신은 실제 열 이름으로 column_name을 대체해야합니다 :) 예를 들어 귀하의 경우에 그것은 이전에 레일을 추가합니다. add_l_name_to_student l_name : string –
나는 부울을 추가하는 것 외에는 똑같은 일을했습니다. 내가이 명령을 실행할 때 "undefind variable 또는 main 메서드에 대해 'boolean'을 얻습니다 : Object – Nick