A gem that allows you to manipulate hashed values in the same way as Active Record Convenient because you can also paste Relation
You can write as follows
app/models/plan.rb
class Plan < ActiveHash::Base
self.data = [
{id: 1, name: "free"},
{id: 2, name: "silver"},
{id: 3, name: "gold"},
]
end
class Plan < ActiveHash::Base
self.data = [
{id => 1, name => "free"},
{id => 2, name => "silver"},
{id => 3, name => "gold"},
]
end
class Plan < ActiveHash::Base
fields :name
add id: 1, name: "free"
add id: 2, name: "silver"
add id: 3, name: "gold"
end
Terminal
pry(main)>Plan.first
=> #<Plan:0x00007ffd3d2c43f8 @attributes={:id=>1, :name=>"free"}>
extend ActiveHash::Associations::ActiveRecordExtensions
belongs_to_active_hash :Active Hash model name
reference https://qiita.com/DON4024/items/78edb7a309ee96766952 https://qiita.com/Toman1223/items/8633142312bfa886d50b
Recommended Posts