2014-08-31 3 views
0

데이터베이스에 내 정적 데이터 (하드 코딩 된) 변수를 넣으려고합니다.레일즈상의 루비에 데이터베이스가없는 모델을 어떻게 사용합니까?

내 컨트롤러에서 사용하고 뷰를 조작하십시오.

레일에서 루비로 어떻게 할 수 있습니까?

당신은 ActiveRecord

# find me in app/models/my_class.rb 
class MyClass 
    attr_accessor :prop1, :prop2, :prop3 
end 

이 같은 컨트롤러를 사용하여 상속하지 않는 app/models/에 클래스를 넣을 수

답변

1

:

# find me in app/controllers/some_controller.rb 
class SomeController < ApplicationController 
    def index 
     @my_class = MyClass.new 
     @my_class.prop1 = "Hello" 
     @my_class.prop2 = "World" 
     @my_class.prop3 = 1 
     # etc. 
    end 
end 
관련 문제