Ruby on rails 如果没有RubyonRails中的数据库,我如何使用我的模型?

Ruby on rails 如果没有RubyonRails中的数据库,我如何使用我的模型?,ruby-on-rails,database,view,model,controller,Ruby On Rails,Database,View,Model,Controller,我想把带有静态数据(硬编码)的变量放在模型中,而不需要数据库- 并将其与我的控制器一起使用并操纵视图 如何在RubyonRails中做到这一点?您可以在app/models/中放置一个类,该类不继承自ActiveRecord # find me in app/models/my_class.rb class MyClass attr_accessor :prop1, :prop2, :prop3 end 在如下控制器中使用它: # find me in app/controllers/

我想把带有静态数据(硬编码)的变量放在模型中,而不需要数据库-

并将其与我的控制器一起使用并操纵视图


如何在RubyonRails中做到这一点?

您可以在
app/models/
中放置一个类,该类不继承自
ActiveRecord

# find me in app/models/my_class.rb
class MyClass
    attr_accessor :prop1, :prop2, :prop3
end
在如下控制器中使用它:

# 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
#在app/controllers/some_controller.rb中找到我
类SomeController