I have two models.
I have two models.
class Tourist < ApplicationRecord has_many :visits has_many :countries, through: :visits end
class Country < ApplicationRecord has_many :visits has_many :tourists, through: :visits end
class Visit < ApplicationRecord belongs_to :country belongs_to :tourist end
I am trying to find a way to sort the countries by the number of tourist associations.
I'm led to believe I should join the tourist's table with countries, then group by tourist before ordering to place the group with the largest count at the top.
However, this doesn't seem to be quite right. Firstly, I get a depreciation warning.
DEPRECATION WARNING: Dangerous query method (method whose arguments are used as raw SQL) called with a non-attribute argument(s): "COUNT()". Non-attribute arguments will be disallowed in Rails 6.0. This method should not be called with user-provided values, such as request parameters or model attributes. Known-safe values can be passed by wrapping them in Arel.sql(). (called from pry at (pry):61)
Also, I don't think I'm getting the correct values because everything after first is nil.
What is the correct way to get the records with the most associations?
Our Ruby on Rails Training will provide you to learn about Rails and web applications development with realty. Our Ruby on Rails Course also includes live sessions.
Click here, free ruby on rails course videos for you. It shows you best way to complete Ruby certification. OnlineITGuru guides you towards easy Web script
Synchronises Assets between Rails and S3. Contribute to AssetSync/asset_sync development by creating an account on GitHub.
How do I solve the DoubleRenderError by using before_action.To practice my rails skills, I decided to make a website about events. It is a website mainly between organizations, who hold an event and volunteers, who join the event. Among all the problems I encountered, I want to share the DoubleRenderError because it bothered me for a long time and how I solve the problem.
There are times when one as a Ruby on Rails developer wants to implement a real-time feature, like a chat application, and after digging a bit you find a framework's feature named ActionCable, sounds new and scary, right? Fear not, I'll try to explain it as simple as possible so that at the end of this article you'll feel comfortable with the subject.