Data dodania Pytanie
2017-08-10 19:08 how to order of has_many through by a specific field »
I have 3 models: member, team, and team_enrollment. The structure is as follows: class Member < ApplicationRecord has_many :team_enrollments ...
(1) odpowiedzi
2017-08-10 19:08 Rails 5 - Using scope method with associated models query »
I am trying to create a scope method that queries only records that have been recently updated (or their associated models have been recently updated)...
(1) odpowiedzi
2017-08-10 03:08 How to properly scope and optimize this model queries in Rails 5 with AR »
I have an API with Rails 5.0.5 in API mode. On every controller request we respond with render json: using Active Model Serializers. We use postgresq...
(1) odpowiedzi
2017-08-09 17:08 How to convert a plain sql query with subqueries to use rails active record »
I have tried converting this plain sql query to rails active record but I am unable to do so. select vote_shares.election_year as vs_election_nam...
(2) odpowiedzi
2017-08-07 16:08 Get all records that exist in both the tables »
Below are two tables with some sample data :- Uploads: id: 1 , file_ref:abc id: 2, file_ref: abc1 id: 4, file_ref: abc3 id: 5, file_ref: abc4...
(3) odpowiedzi
2017-08-07 15:08 How to get latest comments from each post in Rails? »
I have a standard blog models, user, posts and comments. How can I query for 1 latest comment of each post of custom user? I know we can connect user...
(2) odpowiedzi
2017-08-06 18:08 Rails: How to make recent blog posts appear first »
I'm creating a blog app with ruby on rails. I was able to allow a user to add posts, but on the top of the page, the posts that were created first app...
(3) odpowiedzi
2017-08-03 20:08 Error handling of csv upload in rails »
I have this import method in my active record which I use to import the csv file. I want to know how to do the error handling of this in the active re...
(1) odpowiedzi
2017-08-03 15:08 Activerecord store only returns empty hash after rails 5 upgrade »
I am in the process of upgrading a rails 4.2 application to rails 5. One of the models uses an ActiveRecord::Store. When retrieving records after the ...
(0) odpowiedzi
2017-08-03 02:08 Ruby NoMethodError: undefined method `messages' for []:Array »
Since google did not help me in my quest to figure this out, I figured I would share it for anyone else that runs into this problem: When attempting ...
(1) odpowiedzi
2017-08-02 17:08 Mimic Active Record Relation Render Behavior »
I would like to mimic the rendering behavior of ActiveRecord::Relation in my own class. Specifically, when you instantiate an ActiveRecord::Relation, ...
(1) odpowiedzi
2017-08-01 17:08 Rails skip certain columns on Save/Update with different locales »
While saving/updating in rails, is it possible to skip/disregard a column if conditions are met in before_save callback ? Like for example I have a P...
(1) odpowiedzi
2017-07-31 22:07 Save multiple foreign keys in one model attribute »
I am new to Rails. Currently I am developing Rails 5 API. There are two models. BLOCK block_name -------------------------------- EMPLOYEE name emai...
(1) odpowiedzi
2017-07-31 16:07 Find all students not enrolled in specific course »
I am trying to solve this one but no success till now. I have 3 models. Course Model: class Course < ActiveRecord::Base has_many :student_co...
(2) odpowiedzi
2017-07-31 08:07 Difference between Model.offset().limit() and Model.limit().offset() »
I don't understand the reason for doing Model.limit(6).offset(5) when we have to get 6 elements starting from the 6th index. I think that it should be...
(3) odpowiedzi
2017-07-28 21:07 How do I store an entire object in a through table with Rails and ActiveRecord? »
I need to be able to store an entire object's values in a Rails serialized ID hash in a "through" table. What is the proper way of setting up the mode...
(0) odpowiedzi
2017-07-28 14:07 Silent failure in creating child record even with create! in Rails - expected behaviour or bug? »
I ran into a weird issue recently where my previously working code for User creation stopped working without any change in the model or controller. I ...
(0) odpowiedzi
2017-07-27 19:07 calling scope with parameter with .from method »
Is it possible to call a scope with parameter in ActiveRecord query using instance methods like from (e.g. with a symbol of a scope)? How would I do t...
(0) odpowiedzi
2017-07-27 18:07 What should I name my fixture file for a model with the name Mls »
I have an activerecord model Mls in the directory app/models/mls.rb. I have the corresponding fixture in test/fixtures/mls.rb. When I run rails tes...
(0) odpowiedzi
2017-07-27 11:07 Which one is faster between map, collect, select and pluck? »
I have been using different methods to get specific field from active record. But which one is faster and preferred and how are they different? User....
(2) odpowiedzi
2017-07-26 03:07 How to get the exact matched record in rails 3? »
Items in the database: => [#<Item id: 1, item_collection: [:LAPTOP, :COMPUTER, :MOUSE, :SPEAKER]>, #<Item id: 2, item_collection: ...
(1) odpowiedzi
2017-07-25 21:07 Namespaced key lookup on Rails 5 association with ActiveRecord »
I have the following models: class Supervision::ApplicationRecord < ActiveRecord::Base self.abstract_class = true def self.table_name_prefi...
(1) odpowiedzi
2017-07-25 10:07 Is the object that comes back as a result of a database query, an array or hash? »
Was wondering what kind of form an object comes back when a query is returned from the database. For example: @Users = User.all I'm thinking that ...
(1) odpowiedzi
2017-07-22 22:07 Get association from custom name »
My Seminar model has a column named teacher_id. That part of the relationship is working. I can call seminar.teacher to retrieve the User who teaches ...
(1) odpowiedzi
2017-07-22 11:07 Rails - return last group (by date) »
I have some data that looks like this: generated_at code 1/7/17 aa 1/7/17 ua 1/7/17 tr 20/6/17 ua 20/...
(1) odpowiedzi
2017-07-21 19:07 Rails active record query table by number of its associations »
I have a foo table that has many bars. How do I find all foos that have more than 5 bars? I was thinking something like Foo.where(bar.length > 5) b...
(2) odpowiedzi
2017-07-20 14:07 rake db:migrate doesnt work after paperclip gem is installed »
Hello guys im coding an instagram like app on rails, after i installed the paperclip gem (5.1) i created a model that i must migrate in the db. as i m...
(1) odpowiedzi
2017-07-19 18:07 Rails: Custom ordering and priority for model »
For a Rails project I am working on, I have a model that has an image and a priority attached to it. So it looks something like this: card: -id ...
(2) odpowiedzi
2017-07-18 06:07 How do you add a custom uniqueness validation to an ActiveRecord model in Rails? »
I was perusing the Ruby on Rails Guides article on ActiveRecord validations and I came across this neat excerpt about the uniqueness validation: T...
(2) odpowiedzi
2017-07-17 05:07 How do I get the nth record for each distinct name in a table in rails? »
Essentially I want to get the nth last record for each distinct name. So if I have a table that looks something like name field1 a 1 b ...
(1) odpowiedzi
2017-07-15 06:07 How to achieve concept of connection list with minimal cost using rails ActiveRecord? »
Say User A is connected to B, then user B is automatically considered to be connected with user A. User has_many connection Connection Table: id, ...
(1) odpowiedzi
2017-07-13 01:07 Casting JSON with ActiveRecord raw query »
Is it possible to make ActiveRecord to cast JSON values from the raw queries somehow? Here's an example where I want to get {"x": 1} result to be cas...
(1) odpowiedzi
2017-07-12 17:07 How to model a doctor and patient appointments in rails? »
Rails and stackoverflow beginner here so please pardon me for any mistakes. I am developing an appointment booking system between doctors and patient...
(0) odpowiedzi
2017-07-12 05:07 rails factory rspec tests failing because of "only_integer" validation in model »
I have a factory for my model 'price' but all rspec tests start failing when I put the validation for price as only_integer. The error i get when i tr...
(1) odpowiedzi
2017-07-10 12:07 Wrong type and format validation on CarrierWave uploader field in ActiveRecord model »
I have User ActiveRecord model, with login, email, avatar string format fields. If I'm trying to save user with {login: 1, email: 1, avatar: 1} with w...
(0) odpowiedzi