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

`include ActiveModel::Model` with class name having more than two words

It seems I am missing the magic of ruby on rails 4. I wanted to create an object which includes ActiveModel::Model but which class name contains two words. Therefore I created app/models/registration_form.rb with the following code: class…
AlexN
  • 1,613
  • 8
  • 21
0
votes
1 answer

Testing assigns with ActiveModel in Rspec

Using Rspec 3.4, I've got a Message class: class Message include ActiveModel::Model end The following controller spec fails: context "with invalid params" do it "assigns a newly created but unsaved message as @message" do post :create, {…
stephenmurdoch
  • 34,024
  • 29
  • 114
  • 189
0
votes
2 answers

ActiveModel association and rails console

So I have created two models: rails g scaffold user name email and rails g scaffold rental_unit address rooms:integer bathrooms:integer price_cents:integer and defined association as follow: class RentalUnit < ActiveRecord::Base belongs_to…
Akadisoft
  • 306
  • 1
  • 2
  • 13
0
votes
0 answers

How do I use serialize for an array attribute in a class using ActiveModel::Model?

I'm using a tableless model to create a form. I want to set one of the model attributes as an array I know the following code doesn't work, but just showing what I want to do: Model: class Quote include ActiveModel::Model include…
massaskillz
  • 283
  • 3
  • 10
0
votes
2 answers

Activerecord data validations

I have three Models Bid, Printer, Order A printer can have many bids but only one an order. Im having trouble validating that exact case, a printer can have many bids, but only one bid per order Are there any validations that have this built in to…
Seal
  • 1,060
  • 1
  • 12
  • 31
0
votes
1 answer

Rails thinks model with attr_accessor is valid but it doesn't

I have a model with attr_accessor and I'm adding an error to this attr_accessor. Why does it valid? The code below is self-explainable, I think: class Dealer < AR::Base attr_accessor :keyword_data def keyword_data=(file) begin …
Alex Antonov
  • 14,134
  • 7
  • 65
  • 142
0
votes
1 answer

How to access oauth_access_tokens to check if there is a token for the user in rails testing

I check there is no model for oauth_access_tokens in rails app but I can use sql to check the tokens. How can I use SQL to check for existence of tokens for specific user. My current solution which is not working is as follow: query = "SELECT…
Akadisoft
  • 306
  • 1
  • 2
  • 13
0
votes
1 answer

Where in source/docs can I find ActiveModel::Errors default error message values?

I'd like to see the default validation error messages that ActiveModel::Errors provides in order that I know what I should expect in order to write test expectations accurately. Can you anyone point me in the right direction please?
jbk
  • 1,911
  • 19
  • 36
0
votes
1 answer

Rails: modelling balance movement

Hello I have 2 models here: class Account < ActiveRecord::Base belongs_to :user has_many :transactions end class Transaction < ActiveRecord::Base belongs_to :account after_create :update_balance def update_balance balance =…
pyfl88
  • 1,680
  • 16
  • 26
0
votes
0 answers

Use active model serializer with rails namespaces

I am in this situation, in my controller I call: render json: @customers_filtered, serializer: User::CustomerSerializer My serializer: class User::CustomerSerializer < ActiveModel::Serializer attributes :id,:firstname end But when I call the…
ciaoben
  • 3,138
  • 4
  • 27
  • 42
0
votes
0 answers

ActiveModel::Serializer with serialized attribute

I have a user model with serialized attributes. I also have a JSON API built with Grape using ActiveModel::Serializer to serialize the JSON. Here are the relevant snippets of code: class User < ActiveRecord::Base serialize :about_me serialize…
Matt
  • 1
0
votes
1 answer

ruby - custom validation is not called

I have two classes; customer and reservation. And my project is consist of only ruby code, not rails project. Class reservation reads bulk json file line by line which includes customer hash. From that hash, I create customer object. Here's the code…
CanCeylan
  • 2,890
  • 8
  • 41
  • 51
0
votes
1 answer

Can we connect few models of a Rails 3 app to different type of database using the ActiveRecord adapter?

Let there is a rails 3 app with two models, a Project and Notification using the ActiveRecord adapter with MySql. Project has various states using state_machine and when its state changes, I want the notifications to be stored and retrieved back…
millisami
  • 9,931
  • 15
  • 70
  • 112
0
votes
1 answer

How to call build on an overwritten getter?

I have overwritten a getter in one of my models for a has_many relationship. The use case for this is that it builds 'fake' (non-persisted) objects that are scheduled tasks, purely for the purpose of displaying them on a calendar. For example, task…
0
votes
1 answer

Auto-assigning objects to users based on priority in Postgres/Ruby on Rails

I'm building a rails app for managing a queue of work items. I have several types of users ("access levels") to whom I want to auto-assign these work items. The end goal is an "Auto-assign" button on one of my views that will automatically grab the…