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
2
votes
2 answers

Type safe Rails 3 Tableless Model

This Railscast describes how to set up a tableless model in Rails 3 as in: class Message include ActiveModel::Validations include ActiveModel::Conversion extend ActiveModel::Naming attr_accessor :name, :email, :content …
Jamie McCrindle
  • 9,114
  • 6
  • 43
  • 48
2
votes
3 answers

Deploying to Rails project to Heroku: Could not find activemodel

I am relatively new to rails and have been working my way through the Michael Hartl Tutorial. Throughout I have been deploying my projects to Heroku, however now I am at the end of chapter 5, I am getting an "application error". Specifically I am…
2
votes
2 answers

ActiveModel fields not mapped to accessors

Using Rails 3 and ActiveModel, I am unable to use the self. syntax to get the value of an attribute inside an ActiveModel based object. In the following code, in save method, self.first_name evaluates to nil where @attributes[:first_name] evaluates…
drsquidop
  • 428
  • 4
  • 12
2
votes
2 answers

Rails: Getting list of attributes with uniqueness validations from a model

Just wondering if it's possible to return a list of all attributes which possess a uniqueness validation? For example, I have a model Person - I'd like to return a list of the attributes in 'Person' which have a uniqueness constraint. Any ideas?
PlankTon
  • 12,443
  • 16
  • 84
  • 153
2
votes
1 answer

Trouble implementing ActiveModel with class attributes on using DelayedJob

I am using Ruby on Rails 3.0.9 and DelayedJob 2.1 and I am trying to implement a "Contact Us" form myself using ActiveModel functionalities. So... ... in my model file I have: class ContactUs include ActiveModel::Conversion include…
Backo
  • 18,291
  • 27
  • 103
  • 170
2
votes
1 answer

Rails, creating a callback

I want to use an ActiveModel callback to be called after an object has been voted on, the issue is that the gem I'm using (voteable_mongo) to make the model votable doesnt provide like a vote model or callback in my app, so how can I create a…
JP Silvashy
  • 46,977
  • 48
  • 149
  • 227
2
votes
2 answers

ActiveModel::SecurePassword undefined method `password_digest='

I try to use rails 3.1 ActiveModel::SecurePassword by following http://bcardarella.com/post/4668842452/exploring-rails-3-1-activemodel-securepassword and I end up with red light ... user.rb class User < ActiveRecord::Base has_secure_password …
2
votes
1 answer

ActiveModel::Serializers::JSON - How to map an array of JSON from a returned string to an collection of Ruby objects

I have code that works for a single instance but the API I am consuming returns an array of data. I have a class to encapsulate this data: class Brewery include ActiveModel::Serializers::JSON attr_accessor :id, :name def attributes=(hash) …
Rig
  • 1,276
  • 3
  • 22
  • 43
2
votes
1 answer

Rails: How should I run my associated objects' callbacks before the parent's callbacks?

I have an Invoice model, which has_many :line_items. Both models have before_validation callbacks. The invoice's callback requires that the line items' callbacks have been run first. However, by default the invoice's callback gets run, then the…
nfm
  • 19,689
  • 15
  • 60
  • 90
2
votes
1 answer

Rails 6 + Mongoid 6.1.0 not compatible versions for gem "activemodel"

Trying to use Rails 6.0.0 with Mongoid 6.1.0 gem 'rails', '~> 6.0.0' gem 'mongoid', '~> 6.1.0' Tried already to not set the mongoid version in Gemfile, but still not working. Bundler could not find compatible versions for gem "activemodel": In…
pipinha
  • 195
  • 1
  • 10
2
votes
3 answers

Rails 3 form error: "undefined method `quoted_table_name'"

I have a Rails 3 form (simple_form, really) that has a set of nested attributes: <%= simple_form_for(@user, :url => the_path(@user)) do |f| %> ... <%= f.simple_fields_for :credit_card do |c| %> <%= c.input :number, :label => 'Credit card…
Devin
  • 851
  • 12
  • 32
2
votes
3 answers

Rails - check if parent object was destroyed and is calling destroy on dependents

I have the following: class ModelA < ApplicationRecord has_many :model_bs, dependent: :destroy end class ModelB < ApplicationRecord belongs_to :model_a after_destroy :action_only_if_model_a_exists private def…
bdx
  • 3,316
  • 4
  • 32
  • 65
2
votes
2 answers

Rails model has_many association to the same model

I have two models: Category and Subcategory And I can have situation that Subcategory will include more Subcategories How Can I do it with rails associations? Now my code: category.rb class Category < ApplicationRecord has_many :subcategories,…
2
votes
1 answer

Rails 3: Where to store shared methods for models?

I have a method "random_password" that I'd like to be able to access from multiple models in my rails 3 project. I'm just wondering what the convention is for where to store it & how to provide access to it. Any help appreciated.
PlankTon
  • 12,443
  • 16
  • 84
  • 153
2
votes
2 answers

Retrieving Rails 3 model with XML column

I have a Rails 3 model that includes a XML column in the database (IBM DB2). Whenever I try to retrieve this model in the XML format by @model.to_xml, I get as result the XML column escaped, something like this: 1
Henrique Zambon
  • 1,301
  • 1
  • 11
  • 20