In my Rails 4 application I have a (non-ActiveRecord) model containing the plans that a user can subscribe to:
class Plan
PLANS = {
'free' => { :name => "Free", :amount => 0, :interval => '', :maximum => FREE_MAXIMUM },
'basic_monthly' => { :name => "Basic", :amount => 500, :interval => 'month', :maximum => BASIC_MAXIMUM },
'basic_yearly' => { :name => "Basic", :amount => 5000, :interval => 'year', :maximum => BASIC_MAXIMUM },
'premium_monthy' => { :name => "Premium", :amount => 1000, :interval => 'month', :maximum => PREMIUM_MAXIMUM },
'premium_yearly' => { :name => "Premium", :amount => 10000, :interval => 'year', :maximum => PREMIUM_MAXIMUM }
}
def self.all
...
end
def self.all_payable
...
end
def self.by_interval(interval)
...
end
end
I have worked with ActiveRecord a lot but in this case I don't know how to filter the hash values so I can render them out to the front end.
class PagesController < ApplicationController
def pricing
@plans = Plan.all
end
end
How can this be done?
Maybe my approach is entirely wrong and it's easier to store the plans in an array?
Thanks for any help.
Enumerable#find_allorEnumerable#selectand then in the block use standardHashaccess methods