
Security News
Meet Socket at Black Hat Europe and BSides London 2025
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.
active_resource_associatable
Advanced tools
This gem is used to establish the association between your ActiveResource class to ActiveRecord class. Why? Because there is no other ruby library to provide such functionality. Its simple and taking care of all options, scopes etc with your associations.
Add this line to your application's Gemfile:
gem 'active_resource_associatable'
And then execute:
$ bundle
Or install it yourself as:
$ gem install active_resource_associatable
include ActiveResourceAssociatable in your ActiveRecord or ActiveResource model. Now you can easily call the methods of either of your ActiveRecord or ActiveResource models. This gem facilitates you to call ActiveResource objects in the same way as you call in any of your ActiveRecord model. It supports calls has_one_activeresource, belongs_to_activeresource, has_many_activeresources, has_and_belongs_to_many_activeresources and has_many_through_activeresources.
Account is non ActiveResource class which is maintaining has one relationship with ActiveRecord class User.
class UserResource < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
belongs_to_activeresource :account
end
class Account < ActiveRecord::Base
include ActiveResourceAssociatable
has_one_activeresource :user, class_name: 'UserResource'
end
Whereas Reader is a ActiveResource class, but maintaining has one relationship with Account.
class Reader < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_one_activeresource :account
end
class Account < ActiveRecord::Base
include ActiveResourceAssociatable
belongs_to_activeresource :reader
end
The same example which explained above in Has One ActiveResource section could be an example of belongs_to_activeresource.
belongs_to_activeresource can also be applied in case of ```has_many_activeresources`` associations.
User is ActiveResource class which maintains the has many relationships with non ActiveResource class Book.
class UserResource < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_many_activeresources :books
end
class Book < ActiveRecord::Base
include ActiveResourceAssociatable
belongs_to_activeresource :user, class_name: 'UserResource'
end
Now you can easily call user.books which will return the array of objects of non ActiveResource class Book.
class Library < ActiveRecord::Base
include ActiveResourceAssociatable
has_many_activeresources :readers
end
has_many_activeresources also comes with options class_name.
class Reader < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_many_activeresources :studying_materials, class_name: "Book"
end
class Book < ActiveRecord::Base
include ActiveResourceAssociatable
belongs_to_activeresource :reader
end
Now you can call reader.studying_materials which will return the array of objects of non ActiveResource class Book.
User can also call books using a specific foreign key. For Example,
class UserResource < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_many_activeresources :books, foreign_key: "user_id"
end
active_resource_associatable provides many to many associations between ActiveResource and ActiveRecord.
User class is a ActiveResource class and can have many images. Likewise, Image which is a ActiveRecord class can have many users.
class User < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_and_belongs_to_many_activeresources :images
end
class Image < ActiveRecord::Base
include ActiveResourceAssociatable
has_and_belongs_to_many_activeresources :users
end
You can use class_name and foreign_key as in has_many_activeresources.
class UserResource < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_and_belongs_to_many_activeresources :images, foreign_key: "user_id"
end
class Image < ActiveRecord::Base
include ActiveResourceAssociatable
has_and_belongs_to_many_activeresources :users, class_name: 'UserResource'
end
has_many_through_activeresources can also be achieved using active_resource_associatable. User can have many friends through friendships. Similarly, a friend can also have many users through friendships.
class UserResource < ActiveResource::Base
self.site = ""
include ActiveResourceAssociatable
has_many_through_activeresources :friends, through: :friendships
end
class Friend < ActiveRecord::Base
include ActiveResourceAssociatable
has_many_through_activeresources :users, through: :friendships, class_name: 'UserResource'
end
class Friendship < ActiveRecord::Base
include ActiveResourceAssociatable
belongs_to_activeresource :user
belongs_to :friend
end
After checking out the repo, run bin/setup to install dependencies. Then, run rake test to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.
To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.
Bug reports and pull requests are welcome on GitHub at https://github.com/neerajkumar/active_resource_associatable. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the Contributor Covenant code of conduct.
The gem is available as open source under the terms of the MIT License.
FAQs
Unknown package
We found that active_resource_associatable demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Socket is heading to London! Stop by our booth or schedule a meeting to see what we've been working on.

Security News
OWASP’s 2025 Top 10 introduces Software Supply Chain Failures as a new category, reflecting rising concern over dependency and build system risks.

Research
/Security News
Socket researchers discovered nine malicious NuGet packages that use time-delayed payloads to crash applications and corrupt industrial control systems.