
Yaconf::has는 Rails에서 제공하는 헬퍼 메소드 중 하나로, 모델의 속성을 정의할 때 사용됩니다. 하지만, 이 헬퍼 메소드를 사용하여 모델의 속성을 정의할 때, 속성을 여러 개 정의할 수 없습니다.
Yaconf::has는 하나의 속성을 정의할 때 사용됩니다. 예를 들어, User 모델의 name 속성을 정의할 때는 다음과 같이 사용할 수 있습니다.
#hostingforum.kr
ruby
class User < ApplicationRecord
has :name
end
여러 속성을 정의할 때는, 각 속성을 별도로 정의해야 합니다.
#hostingforum.kr
ruby
class User < ApplicationRecord
has :name
has :email
end
위의 코드에서는 name과 email 속성을 별도로 정의하고 있습니다.
만약, 여러 속성을 한 번에 정의하고 싶다면, Rails의 기본 헬퍼 메소드인 `attr_accessor`를 사용할 수 있습니다.
#hostingforum.kr
ruby
class User < ApplicationRecord
attr_accessor :name, :email
end
위의 코드에서는 name과 email 속성을 한 번에 정의하고 있습니다.
2025-05-24 16:29