Data dodania Pytanie
2017-10-16 23:10 How to sort by a calculated value in Activerecord? »
I have a rails API which returns JSON to my React front end. I'm trying to sort by a calculated value for each item in a collection. I have a Space mo...
(1) odpowiedzi
2017-10-14 19:10 Rails Active Record: Multiple users to CRUD a post created by a different user »
I have two models named User and Post User.rb class User < ApplicationRecord has_many :posts end Post.rb class Post < ApplicationRecord...
(1) odpowiedzi
2017-10-14 01:10 PLUCK one row WHERE postgres column name includes underscore »
I am trying to get a row/rows in a POSTGRES table where a column name with an underscore ("Cas_NO") matches a specific string. I am having trouble for...
(1) odpowiedzi
2017-10-13 16:10 How to write to a join table params? »
I've recently rearanged my application to get some additional functionality. Unfortunately this is first time I'm working with join table and don't kn...
(0) odpowiedzi
2017-10-12 06:10 Rails Model scope chaining based on dynamic scope name list »
Let's say I have some model class MyModel < ApplicationRecord scope :opened, -> { where(status: 'open') } scope :closed, -> { where(stat...
(1) odpowiedzi
2017-10-11 00:10 Rails and Postgres, group by hstore »
I have an 'Audit' model with name:string and data:hstore attributes - as follows: #<Audit id: 1, name: "my audit", data: {"publisher"=>"some...
(2) odpowiedzi
2017-10-09 18:10 Grouping Query with Has Many Relations in Rails »
I have a has_many, through: relationship between Projets and Categories using a Categorization model. A Projet belongs_to a Client. class Client <...
(1) odpowiedzi
2017-10-07 01:10 ActiveRecord Recover associated records »
I have an app which models companies that have users who can even have meals. So I have a Company table, a User table and a Lunch table. The lunch co...
(2) odpowiedzi
2017-10-05 21:10 Rails Active Record query with multiple optional params »
What would be the optimised way to create an ActiveRecord query in a Rails 4.1 application controller which can 0 to 4 optional query params, in absen...
(1) odpowiedzi
2017-10-05 13:10 Couldn't save associated models in rails using auto_save: true »
please consider the following snippet. I have a parent model named Post as: class Post < ActiveRecord::Base has_many :comments, dependent: :des...
(0) odpowiedzi
2017-10-04 21:10 Cannot use group with has_many through in Rails 5 »
I have the following associations: class Student < ApplicationRecord has_many :people_schools has_many :schools, through: :people_schools ...
(1) odpowiedzi
2017-10-03 23:10 ActionController::UrlGenerationError in UsersController#create ... missing required keys: [:id], possible unmatched constraints: [:locale] »
I had some nice form that had been working well, but once I add some translations, I get following error: Here are some important files I have: ro...
(1) odpowiedzi
2017-10-02 23:10 rails active record relationship... inheritance? »
I have multiple user roles: enum role: { staff: 0, clinician: 1, admin: 2 } Staff users create patient records and belong to a university. Staff...
(0) odpowiedzi
2017-10-02 22:10 Rails 5 column group issue »
I am using rails 5.1 and am trying to display some data in a tree format using jstree. It's working by my sorting and grouping is not correct and woul...
(0) odpowiedzi
2017-10-01 15:10 Computing ActiveRecord nil attributes »
In my Rails app I have something like this in one of the models def self.calc columns_to_sum = "sum(price_before + price_after) as price" where('...
(2) odpowiedzi
2017-09-30 13:09 Rails 5 Active record Associations not working »
user can post multiple jobs and at the same time user can apply for the multiple jobs but each user only can single apply for the each job Here is my...
(0) odpowiedzi
2017-09-29 19:09 locking rows on rails update to avoid collisions. (Postgres back end) »
So I have a method on my model object which creates a unique sequence number when a binary field in the row is updated from null to true. Its impleme...
(0) odpowiedzi
2017-09-29 16:09 Creating a full path to sub-directory on a server »
I am currently working on a Rails application and recently received a request to add the ability to go to a sub-directory on the server at work. i.e....
(1) odpowiedzi
2017-09-28 17:09 Rails' ActiveRecord doesn't see tables in SQLite3 database after migration »
I did rake db:drop rake db:create and rake db:migrate. When I run sqlite console, I get the following: sqlite> .tables ar_internal_metadata grou...
(0) odpowiedzi
2017-09-28 05:09 has_one association creates multiple records in rails »
I have a User model and Shop model. I want to allow user to create only one shop. So in my User model class User < ApplicationRecord # Include d...
(1) odpowiedzi
2017-09-27 17:09 Rails- when doing a multiple condition search, how to eliminate the column with nil value? »
A car has three attributes, "model", "location", "status". I want to search cars according these three conditions. First, I thought I could use Car....
(1) odpowiedzi
2017-09-27 14:09 belongs_to touch: true not fired on association.build and nested attribute assignment »
In the OpenProject application we have two models: CustomField class CustomField < ActiveRecord::Base has_many :custom_options, -> { order(...
(1) odpowiedzi
2017-09-27 08:09 Rails 5.1.: get records from association for each datetime interval »
I have Model named Task with method dates which gives me this output (it can be different and multiple DateTime intervals): [{:from=>2017-09-04 00...
(1) odpowiedzi
2017-09-26 17:09 How to connect a rails app to a oracle database? »
I am unable to find step by step instructions on this topic. I want a Rails 5.x app to be able to connect to an Oracle Database. I know that there a...
(1) odpowiedzi
2017-09-26 14:09 Rails: filtering based on a child & parent's attribute calculation »
I have 2 associated tables and would like to apply a filter based on tshirts (child table) length attribute which is +/- %5 of the parent object Stude...
(1) odpowiedzi
2017-09-26 01:09 eager loading not working with order() clause in rails »
I am using this query to get my data user = User.includes(:skills).order(user: :id) it is working fine. but when i try to display skills by alphabe...
(2) odpowiedzi
2017-09-22 07:09 Rails: How to sort by calculated date difference? »
I have a calculated field in my model as follows. class Products < ApplicationRecord attr_reader :days def days (Date.today - self.created_at)...
(3) odpowiedzi
2017-09-21 14:09 how to model a study_program into Rails application »
I'm working a Rails application that enables students to register an absence for an exam. These are the models class User < ApplicationRecord h...
(1) odpowiedzi
2017-09-20 23:09 ActiveRecord select_all prefix table name »
I am able to execute a multi table join with raw sql and activerecord select_all such as g = Group.column_names.map{|f| 'g.'+f.to_s+' AS g_'+f.to...
(0) odpowiedzi
2017-09-20 20:09 Add a column in a Rails Active Record migration with an initial value based on other columns »
I am attempting to add a column to an existing table using an Active Record migration in Rails. I need the column's initial value to be based on othe...
(2) odpowiedzi
2017-09-20 17:09 ActiveRecord Validations : String added to error message in locales »
I'm trying customize validation error messages using i18n. Let's say I have an Address model that validates the presence of a zip_code. My config/loc...
(3) odpowiedzi
2017-09-19 12:09 Convert sql for archives to Rails ActiveRecord »
I'm having this class method inside my Post model for archives class Post < ActiveRecord::Base def self.archives # fetch archives end end ...
(1) odpowiedzi
2017-09-18 17:09 Form in Ruby on Rails: using find and create by in the model »
Does "find_or_create_by" is the key to my problem? Answer No! Below is another suggestion that works. I took over a system. It manages courses and t...
(1) odpowiedzi
2017-09-17 00:09 Sum active record with expression rails »
I have this code in my sql view: SELECT reports.`date` reports.book_title SUM( reports.net_sold_count * reports.avg_list_price / 10 ) AS ...
(1) odpowiedzi
2017-09-15 14:09 Rails: How to sort based on Average, Sum, Count with Associated Models? »
I have 2 associated tables as follows, and currently I have a reporting page which displays average, count, sum etc.. I would like to add sorting func...
(2) odpowiedzi