Questions tagged [activemodel]

A toolkit for building modeling frameworks like Active Record. Rich support for attributes, callbacks, validations, serialization, internationalization, and testing.

ActiveModel brings many of ActiveRecord's features (such as validations and callbacks) to non-ActiveRecord classes.

707 questions
1
vote
1 answer

Calling a validation from within another custom validation

I want to have two different custom validators, but would like one of the validators to reference the other: class URLFormatValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) # ... validates the format of a URL…
Tom Rossi
  • 11,604
  • 5
  • 65
  • 96
1
vote
1 answer

Bundler could not find compatible versions for gem "activemodel":

Trying to upgrade to rails 5.2.2. Blew away my gem lock file, and then did a 'bundle install' Lot of dependancy errors, but this is the first error and one i really dont understand: Bundler could not find compatible versions for gem…
TexasNeo
  • 592
  • 1
  • 3
  • 12
1
vote
1 answer

NoMethodError: private method `y' in ActiveRecord when accessing an attribute

I have a model Artboard and a model Group that has a many to many relationship through a table called ArtboardsGroups that has attributes for an x and y value pertaining to the relationship class Artboard < ApplicationRecord has_many…
David
  • 377
  • 5
  • 14
1
vote
2 answers

Can I use a JSON-File as datasource in a Ruby on Rails model

I have a JSON-file with some Data and I like to create a Model that represents the Data from the JSON-file like a ActiveRecord class. My JSON looks like the folling (Not the real data just a example): [ { "name": "Test", "model": "L33D", …
Zero Soul Eater
  • 132
  • 1
  • 13
1
vote
4 answers

Datatype validation in rails ActiveModel::Validations

I wanted to validate class attributes with respect to their data type. I am writing an API in ruby and i need to check if a particular parameter data is of type String, hash, Array etc. eg. we have class ApiValidation include…
1
vote
1 answer

ActiveModel::ForbiddenAttributesError in UserController#register

Im trying to register users on my rails site. When I click the register button on the register page this is what shows up: ActiveModel::ForbiddenAttributesError in UserController#register ActiveModel::ForbiddenAttributesError Here is the code…
1
vote
1 answer

Rails ActiveModel designing belongs_to and has_many with single class

I need some help modeling my models and controller. Here is what I want to achieve: I want to have a devise user named User (as usual) and a second model named Project. A Project should belong to a single User and at the same time should have many…
1
vote
0 answers

How do you require Active Model Associations?

I'm trying to use Active Model Associations without Rails...how do I require it? require 'active_model' require 'activemodel-associations' class Base include ActiveModel::Model include ActiveModel::Associations end `require': cannot load…
Allyl Isocyanate
  • 13,306
  • 17
  • 79
  • 130
1
vote
2 answers

Why does my production logs show an ActiveRecord::RecordNotUnique error but my local binding.pry shows me an ActiveModel::Errors?

I have a signup form that contains validations on the model and database to prevent duplicate entries. I use honeybadger in production for my error logging. When a user attempts to sign up with the same credentials, honeybadger reports a…
wheresmyspaceship
  • 870
  • 2
  • 12
  • 19
1
vote
2 answers

Detect <,>, >=,<= operators in Ruby and use in .where method (no active record)

In plain ruby (no active record) def where(options) end The options could be key, value pair, or a comparison like >,<,>=, <= If I have an array of records... record = Struct.new(:name, :address, :amount) How to I test which and filter on…
user2012677
  • 5,465
  • 6
  • 51
  • 113
1
vote
2 answers

Howto optimize an ActiveRecord query with sums on several categories

Models: User has_many Categories, has_many Entries Category has_many Entries Entry belongs_to both Category and User Let's assume, there is a name and an amount on entries. If I have a view that needs to display a particular month (let's take…
Markus Proske
  • 3,356
  • 3
  • 24
  • 32
1
vote
0 answers

Ruby error: undefined local variable or method `c'

I am working on a ruby application but getting a strange error that I believe might be caused by activerecord/activemodel. The error is as follows: Error on PaymentTransaction::Normal: undefined local variable or method `c' for…
dagnyc
  • 29
  • 4
1
vote
1 answer

How to rely on Dirty models when the changed attributes are clean within "after callbacks"?

I'm trying to use ActiveModel::Dirty/ActiveRecord::AttributeMethods::Dirty in views (e.g. in update.js.erb) this way: <% if @product.saved_change_to_attribute?(:name) %> alert("Name changed!") <% end %> In my controller I have: class…
Backo
  • 18,291
  • 27
  • 103
  • 170
1
vote
1 answer

Rails nested model conversion to and from database without its own table

Background: I'm trying to refactor my code after reading Practical Object Oriented Design in Ruby (it's awesome), and in doing so, I want to introduce some more models that encapsulate responsibility, rather than have a single large file with logic…
chr0nikler
  • 468
  • 4
  • 13
1
vote
1 answer

Bundler not finding current ActiveModel when updating Rails

Trying to update a Rails 4.2.9 app to Rails 5.2.1. Changed the Gemfile: gem 'rails', '5.2.1' But Bundler appears to not be able to find an appropriate version of ActiveModel (which is not specifically called out anywhere in the Gemfile). I have…
Meltemi
  • 37,979
  • 50
  • 195
  • 293