Data dodania Pytanie
2017-01-24 22:01 Rails scope with combined attributes »
I am trying to create a scope where checkin_time (DateTime) is added with duration (Int) in hours which is greater than or equal to Time.now So somet...
(1) odpowiedzi
2017-01-24 22:01 Rails: ActiveRecord using where with a custom comparator »
I have a model called Update which contains column :version which is a string. class Update < ApplicationRecord validates_presence_of :version e...
(2) odpowiedzi
2017-01-24 17:01 How to delete a collection matching a condition »
I would like to delete all posts associated to every user of my application matching a determined condition. In particular I would like to delete all ...
(1) odpowiedzi
2017-01-23 12:01 Rails eager loading associations »
I have two models MSellingStaff and MPosition #m_selling_staff.rb class MSellingStaff < ActiveRecord::Base belongs_to :m_position end #m_posit...
(3) odpowiedzi
2017-01-21 21:01 Rails - Object Available in View, but Not Object's properties? »
I've got an unusual problem where I can access an Object, but not its properties in a view. Any Assistance, guidance, is greatly appreciated. This ...
(2) odpowiedzi
2017-01-21 20:01 Rails with FactoryGirl, parent-child association. Omit creating one more record in child model »
I have two models. Parent model Tag: class Tag < ApplicationRecord has_many :keywords, inverse_of: :tag, dependent: :destroy accepts_nested_at...
(2) odpowiedzi
2017-01-19 14:01 before_remove to abort removal crashes server when throwing exception »
I'm using Rails 5's Association Callbacks. I read in the documentation that if you want to abort an object removal from an association you have to thr...
(1) odpowiedzi
2017-01-17 20:01 `find_or_create_by!` and an `after_initialize` callback »
We have something like: class User < ActiveRecord::Base #... after_initialize do |user| # stuff1 end end User.find_or_create_by!(email:...
(0) odpowiedzi
2017-01-17 13:01 Rails validations with enum »
I have an enum in my Box model enum box_type: [:wooden, :plastic, :metal, :paper] and I want the box_type attribute of my Box model to be only one ...
(1) odpowiedzi
2017-01-15 12:01 Rails Job Doesn't Proceed after rails jobs:work »
I have a job in my rails app which I was running it before like a charm with this command: rails jobs:work but it doesn't proceed any longer.I kill...
(1) odpowiedzi
2017-01-15 11:01 ActiveRecord's serialize converts integers to strings? [Rails] »
When I am persisting a hash as a JSON, I expect the hash to be converted to JSON and not modified, but instead the keys are changed from integer to st...
(2) odpowiedzi
2017-01-13 22:01 Rails 5 ActiveRecord - check if any results before using methods »
In my Rails 5 + Postgres app I make a query like this: user = User.where("name = ?", name).first.email So this gives me the email of the first user...
(3) odpowiedzi
2017-01-12 02:01 How to create a new record using the values from a variable already under the same class »
I remove records all the time to test, and need to re-create the same record to test again. So doing this: User.create(name: "Peter", col1: "etc", ...
(3) odpowiedzi
2017-01-11 23:01 How do I merge parent array and one child with different attribute? »
I have comments and likes (acts_as_votable gem). I want to create one activity list and sort by created_at for comments and updated_at for votes. @ac...
(1) odpowiedzi
2017-01-10 22:01 ActiveRecord Rollback when trying to save to database »
I am building a fairly simple album review application. I am attempting to set up a simple_form for new reviews. The change will not stick. This is wh...
(1) odpowiedzi
2017-01-10 16:01 Ruby on Rails - where query with Time parse »
How can I select all records where the date is past? I have "Date" column with format : '%m/%d/%Y' e.g "01/10/2017". Column type is string, I can't c...
(3) odpowiedzi
2017-01-09 23:01 ActiveRecord read replica for reporting queries »
I have a Rails/ActiveRecord application that occasionally executes some heavy read-only queries against the application's models for ad-hoc admin/repo...
(0) odpowiedzi
2017-01-06 13:01 How to create migration script for has_many, belong_to association between user and task model in ruby »
I have two model User and Task. Task would have one owner and other as workers. class Task < ApplicationRecord belongs_to :user has_many :...
(1) odpowiedzi
2017-01-06 00:01 rails controller find record with no associations »
Student has_many enrollments Is there a way to see only students that have no enrollments? Something like: @students = Student.includes(:enrollmen...
(1) odpowiedzi
2017-01-05 23:01 Rails Active Record Query joins only, any »
Student has_many :enrollments With this query I see those students that have true enrollments, but also those that have both, true and false enrollm...
(1) odpowiedzi
2017-01-05 05:01 Have access to multiple databases »
I am developing an application that at the beginning the user can select which database to connect to. It is a Rails application which uses Active-Rec...
(0) odpowiedzi
2017-01-04 20:01 List the number of records that have X number of associations in has_many »
I have my Person class which will have 0 or more widgets associated class Person < ActiveRecord::Base has_many :widgets end I'd like to list o...
(2) odpowiedzi
2017-01-04 14:01 Querying hstore with exists? »
I have a column as postgres hstore, and want to query it with exists? in my model. I am using Model.where("column ? :key", key: "xxx").count but ...
(1) odpowiedzi
2017-01-04 13:01 has_many relationship using FactoryGirl »
I'm trying to create instance with has_many relationship using FactoryGirl factories and fail. I have two classes: Computers and NetworkCards. Each Co...
(2) odpowiedzi
2017-01-03 22:01 Passenger Ignoring RAILS_ENV »
Background I've got an env file with various variables depended upon by my Rails app, including RAILS_ENV, which is initialized to development in thi...
(1) odpowiedzi
2017-01-03 16:01 Optional where in Rails »
How can I make a where optional in Rails? I tried: @pages = Page .where(status: params[:status].present? ? params[:status] : 1) ...
(2) odpowiedzi
2017-01-03 00:01 how to count on unique records of public_activity actions in rails? »
I am using public_activity gem. @num = PublicActivity::Activity.where(owner_id: current_user.id, key: "micropost.read").count This would show corre...
(1) odpowiedzi
2017-01-01 22:01 Sort list of objects according to an array (Rails) »
I have an array if ids from a table e.g: b = [659, 658, 656, 645, 644, 657, 634, 643, 649, 650, 651, 636, 633, 607, 605, 604, 648, 647, 675, 674, 667...
(3) odpowiedzi
2016-12-31 21:12 NOT NULL constraint failed created_at when saving model »
I'm getting an exception when I call save! in a model. SQLite3::ConstraintException at /contacts/import_spreadsheet/1/import NOT NULL constraint...
(0) odpowiedzi
2016-12-30 17:12 Use Rails' select() to add (not overwrite) selected attributes? »
I have a convenience scope that includes related models to speed up rendering of tables, etc: class Post < ApplicationRecord ... scope :inclu...
(1) odpowiedzi
2016-12-29 15:12 Model's attributes are being failed validation when they are not passed »
Is it logical that when I don't pass attributes' values, they failed the validation of the custom validation method, even though I am not trying to up...
(0) odpowiedzi
2016-12-28 18:12 Rails 5 belongs_to default behavior »
begin require "bundler/inline" rescue LoadError => e $stderr.puts "Bundler version 1.10 or later is required. Please update your Bundler" rai...
(1) odpowiedzi
2016-12-28 18:12 ActiveRecord Complex Query »
I need some advice on how I should be going about some business logic in our app. Currently I have a loop for returning all of a user’s sales opport...
(0) odpowiedzi
2016-12-28 13:12 Rails: How to show items only if creator is unique? »
I have many users and each user has multiple projects. Now, I want to get only one item per user. @projects = Project.all.where(user_id is unique) ...
(2) odpowiedzi
2016-12-26 19:12 Rails join on user column »
I'm trying to get all Activities related to users of the same school (a string on the user object), but the error I'm getting is this: Can't join...
(1) odpowiedzi