Francisco Perez
Francisco Perez

Reputation: 1

How can I work with my model without a database in ruby on rails?

I want to put my variables with static data (hardcoded) in the model -without database-

and use it with my controller and manipulate the view.

how I can do this in ruby on rails?

Upvotes: 0

Views: 128

Answers (1)

Paul Oliver
Paul Oliver

Reputation: 7671

You could put a class in app/models/ that doesn't inherit from ActiveRecord

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

Use it in a controller like this:

# 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

Upvotes: 1

Related Questions