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
0
votes
1 answer

Validating uniqueness without database in model specs

I have a model that looks something like this: class User include Mongoid::Document field :email validate :email, presence: true, uniqueness: true end And I have a test that looks like... it { User.new.should_not be_valid } it {…
Drew
  • 15,158
  • 17
  • 68
  • 77
0
votes
0 answers

Rails 3/Mongoid: calling a validator on a collection when updated

I am working in Mongoid 3 and Rails 3. I want a validator to be called on a model after its collection is modified: class TooManyValidator < ActiveModel::EachValidator def validate_each(record, attribute, value) puts "validate called" if…
GTDev
  • 5,488
  • 9
  • 49
  • 84
0
votes
2 answers

Using ruby inject to compare value from table with activemodel updated attributes

I'm building a custom profile completeness tool in Rails 3.1. Using active_admin, the administrator wants to be able to pick model attributes and assign a score value to them. I create a table with 'name' and 'score' in it. The name being the column…
0
votes
1 answer

Fat model, activeModel or in the controller?

My question has to do with data modeling. We have a Score-model which links to both a Division model and a Element model. Between the Division and the Element model a habtm-relation exists. The score has to be evaluated against an attribute of the…
0
votes
3 answers

How to use validates_uniqueness_of with ActiveModel?

I'm using ActiveModel to make my tableless models feel like ActiveRecord models. I'm using a custom store and I need to be able to validate uniqueness of a record. How can I implement the required uniqueness check using ActiveModel?
Roman
  • 10,309
  • 17
  • 66
  • 101
0
votes
1 answer

Validation says column is not unique, but still can't find record by that column

I have a method which can create a user from facebook user accounts. I validate email column to make sure it is unique. class User < ActiveRecord::Base validates :email, :'validators/email' => true, allow_nil: true, uniqueness:{…
lulalala
  • 17,572
  • 15
  • 110
  • 169
0
votes
1 answer

Assigning two models of the same type to another model in rails

I've got an interesting problem in rails Let's say i have a model and i'd like to attach two other models to it, of the same type, but these two should be seperated. Let's say we have a dog, and a dog can have trainers, as well as an owner, but…
tis.sandor
  • 171
  • 1
  • 4
  • 12
0
votes
1 answer

Active Record find via parent's foreign key

Let me display a sketch of needed models: 1) I've a Unit model it's connected (has a foreign key) to the Type model. has_many :People 2)Type - it's a simple model, a string 'name' - like ('first','second', etc) 3) Person model - just a person. What…
Elmor
  • 4,775
  • 6
  • 38
  • 70
0
votes
1 answer

Rails 3: Mongoid validation issue

Using Mongoid, I am trying to validate the :code input on the submission form to make sure they are using a proper code that is already stored in the database. There are about 2000+ codes so a helper method array collection wouldn't be…
0
votes
1 answer

Rails 3: Mongoid validates_inclusion_of error

class Request include Mongoid::Document field :code, type: String validates :code, :presence => true, :inclusion => { :in => proc { Listing.all_codes } } Using Mongoid, I am trying to validate the :code input on the…
jbearden
  • 1,869
  • 2
  • 19
  • 23
0
votes
1 answer

Supplying data for a form re-population from a different model

so I have a tricky issue here I'm not sure how to solve. I have a Provider model that has_many :educational_affiliations EducationalAffiliation belongs_to :institution & belongs_to :provider I have about 9000 universities in my database, so I'm…
MBHNYC
  • 1,268
  • 1
  • 13
  • 25
0
votes
1 answer

Rails: How can I implement this relationship between these models? habtm? habtm through? Polymorphic?

I am storing my files on Amazon s3. Each file has many "consumers" and these consumers can be of any type(users, external apps, business_listings, etc). This calls for a many to many relationship. However, I also want to store certain attributes…
0
votes
1 answer

Imposing constraints on a populated database (with records that violate these constraints)

I have a model, Clients and a corresponding database with lastname and firstname columns. Originally there were no constraints on the uniqueness of [lastname, firstname], and the database currently contains duplicates. I would like to clean up the…
Alexei Danchenkov
  • 2,011
  • 5
  • 34
  • 49
0
votes
2 answers

How to update attributes only if the params are defined?

currently in my update controller method I have: @group.attributes = { :title => params[:group][:title], :description => params[:group][:description], :password_required => params[:group][:password_required], :password =>…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
0
votes
1 answer

JRuby ActiveRecord/ActiveModel not creating methods and attributes for table columns (undefined method)

I am using JRuby 1.6.7, ActiveRecord 3.2.3, activerecord-jdbc-adapter 1.2.2, activerecord-jdbcsqlanywhere-adapter-1.1.1 and the current Sybase JDBC4 driver. Using a full Ruby On Rails application is not an option at this time. I am getting the…