How to use Apartment gem in Rails 7 - ruby-on-rails

Apartment gem is not working in Rails 6 and Rails 7 projects - it failes on undefined method `new' for "Apartment::Reloader.
Is there good way howto solve this problem? Or is there any good replacement of this gem? We need it for a new big project...

While SO is not the ideal platform for recommendations, I often find ruby-toolbox to be a good source:
https://www.ruby-toolbox.com/categories/Multitenancy

As I know, the apartment gem is no longer actively maintained by its owners and therefore has been forked into what is now known as ros-apartment gem. It works with Rails 6 as I have used it but yet try with Rails 7.
You can also use act_as_tenant gem which works fine with Rails 6 and 7.
The difference between the two is that ros-apartment uses a schema or database (depending on the database type) approach while act_as_tenant uses a row base.
The links below are the documentation sources for the gems
ros-apartment
act_as_tenant

You don't need the Apartment gem if working with rails 6/7 to implement multitenancy at the db level. Rails natively supports connection switching that can be used to implement this. See https://guides.rubyonrails.org/active_record_multiple_databases.html. If you want table level tenancy, then I believe acts_as_tenant works for this.
I have implemented the former on a project.

Related

Switch from Milia to Apartment - keep data?

We have a product that has been built using the milia multi-tenanting gem (https://github.com/jekuno/milia) . Unfortunately it seems this gem is dead. We can't upgrade past Rails 5 because of this.
Is there any way to move from milia to another gem (eg apartment https://github.com/influitive/apartment - though I see that hasn't been updated in 2 years either!) and not force everyone to recreate passwords etc?
I ended up modifying Milia to work with Rails 6.
That new gem is called Philia
Had the same issue trying gem milia had to use acts_as_tenant- which is well upto date and supports rails 5.2 upwards and its syntax close to gem 'acts_as_tenant'
https://github.com/ErwinM/acts_as_tenant

The rails way of doing client side validation (Rails 4 with simple_form)

I am new to Rails and using Rails 4. I have started some forms for creating/editing some models and have added some validation which works fine on the server side.
I assumed that Rails would have something built in to handle client side validation - turns out it doesn't.
I have searched on google and found 'client_side_validation' which is no longer maintained and I don't think works in Rails 4 anyway.
There doesn't seem to be an obvious go to library for Rails client side validation. So what is the 'Rails way' of handling this? Roll your own? Duplicate the logic client side using jQuery? Use html5 validation and fall back to server side when it isn't their? Or is there a library (preferably one that works with simple_form) that I can just install and use?
There is client_side_validations, but is not longer maintained. Probably the best way is using some jQuery plugin like jquery-validation.
Rails 4 + Simple form : To install "Client side validations" with simple_form successfully, you should check for latest versions direct from Github with latest branch.
The released gems don't work with Rails >= 4.0
gem 'client_side_validations', github: 'DavyJonesLocker/client_side_validations'
gem 'client_side_validations-simple_form', github: 'DavyJonesLocker/client_side_validations-simple_form'
Make sure your gem file does not use these versions
client-side Validation 3.2.5
client_side_validations-simple_form 2.1.0
These versions does not support rails 4.2.0
For more detail please check this link,
https://github.com/DavyJonesLocker/client_side_validations-simple_form/issues/41
One way to achieve this is in Rails 4 is to use the client side validation gem: http://rubygems.org/gems/rails4_client_side_validations
This guy here is using it: Client Side Validations and Rails4
Railscasts provides a good tutorial (Rails 3) on it here:
http://railscasts.com/episodes/263-client-side-validations
I was able to use a fork of the original client_side_vlaidations that is very active at the moment. I am using the latest version of simple_form, rails 4.1.8, and this client_side_validations. Simple setup with basic config.

JasmineRice on Rails 4

Has anyone tried JasminRice gem with Rails 4?
I've got Ember Rails 4 app and I would like to use Jasmine Rice but I'm not sure whether it would work out well as their Github account says Pain free coffeescript testing under Rails 3.1
Jasmine Rice
I would advice you to use jasmine-gem, which recently gained Rails 4 support. jasmine-gem is developed by Pivotal, the company that develops Jasmine itself, and is actively maintained. While this gem was very basic for a long time, it has improved tremendously, especially with version 2.0.0. Spec execution in Phantomjs (in addition to the browser, which is the fastest for development) is supported, and there is full integration into the Asset Pipeline, which lets you e.g. write tests in CoffeeScript. At my student job, we are using jasmine-gem extensively and are very happy with it.
In the jasminerice installation section they mention that it should work on rails 4:
This gem has been tested and run with Rails 3.1 and 3.2. It should
also run on Rails 4.
"Should" is not as strong of a word as I would like, but I have a ember rails 4 app and jaminerice has not given me any issues.

What is the backport of Rails 3 style finders (.where) to Rails 2?

I know I've heard of a library that provides Rails 3 style finders (.where) to earlier versions of Rails, but web search is failing me.
I've got a 2.3 project that needs a new feature, and I'd rather use the newer style in case it gets upgraded.
Would something like the Fake_arel gem help?
Fake_arel simulates and supports a variety of features from Rails 3 for earlier Rails versions. The only major requirement is that your currently-used ActiveRecord gem needs to be greater than or equal to version 2.3.5.
The documentation also notes that Fake_arel can be used as a bridge between Rails 2 and Rails 3 apps, which could ease future transitions to later Rails versions.

Is there an updated rails_sql_views gem for rails 3.2?

I need the functionality provided by the rails_sql_views gem. However it looks like the last commit for this gem was made in 2010. Has this project been outdated by a new project? I'd like to find an active gem to use to get this functionality.
http://activewarehouse.rubyforge.org/rails_sql_views/
http://rubygems.org/gems/rails_sql_views
After further research here is a Rails 3 candidate for similar functionality:
https://github.com/bradphelan/Active-Illusion
This is a gem of this blog post:
http://xtargets.com/2011/08/02/tableless-views-with-active-record/
However this solution doesn't seem to be very popular.
schema_plus gem has create_view method that seems compatible (although I'm not familiar with rails_sql_views).
barancw, I needed this gem for our product using Rails 3.2.5, so I forked the repo and updated the necessary pieces. This gem is great for improving the performance of our large database queries, as it reduces the need to load objects into memory. I combined this gem with another optimization: Rails - given an array of Users - how to get a output of just emails?
https://github.com/ryanlitalien/rails_sql_views
Original documentation: http://rubydoc.info/gems/rails_sql_views/0.8.0/frames/index
Please keep in mind the docs are a bit outdated ("require_gem" has been replaced with "gem" and add the gem to your Gemfile as well).

Resources