HStore
PGSQL hStore
:
hstore / PostgreSQL
. , , . .
Heroku , , , .
, Stripe
data
( text
), key:value
(JSON).
, , JSON , . , Rails
# app/models/profile.rb
class Profile < ActiveRecord::Base
end
Profile.create(settings: { "color" => "blue", "resolution" => "800x600" })
profile = Profile.first
profile.settings # => {"color"=>"blue", "resolution"=>"800x600"}
profile.settings = {"color" => "yellow", "resolution" => "1280x1024"}
profile.save!
-
, JSON hStore
:
class ProfilesController < ApplicationController
def update
@profile = current_user.profile
@profile.update profile_params
end
private
def profile_params
params.require(:profile).permit(:x, :y, :z)
end
end
, "" User
.
, @user.interests
. , {name: "interest", type: "sport"}
- .
, / . , , , ActiveRecord association.
, , . , , , ...
class User < ActiveRecord::Base
has_and_belongs_to_many :interests,
class_name: "Support",
join_table: :users_supports,
foreign_key: :user_id,
association_foreign_key: :support_id
end
class Support < ActiveRecord::Base
has_and_belongs_to_many :users,
class_name: "Support",
join_table: :users_supports,
foreign_key: :support_id,
association_foreign_key: :user_id
end
, .interests
.users
:
resources :supports do
post :interest
end
class SupportsController < ApplicationController
def interest
@support = Support.find params[:support_id]
current_user.interests << @support
end
end
@user.interests
Support
.
, .
interest
.
, . many-to-many
.
, , , (u=
, <<
).
, ; , .
, :

def interest_already_sent
support = Support.find params[:id]
current_user.interests << support
end
, , interest
.
.interests
.
Rails Support
(IE support_id
current_user
(IE user_id
) interests
( UserInterestSelf
).
user_id
current_user
support_id
Support
.