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

What is a sensible way to allow the entry of prices into forms in ruby on rails?

Currently building a backend administrators control panel for an iOS app I've developed. From this control panel an admin can add items to a store. One of the properties/attributes of a item would be it's price. I'd like the price in this format…
LondonGuy
  • 10,778
  • 11
  • 79
  • 151
0
votes
0 answers

Nested form (strong parameters) inserting without values (besides id and timestamps)

I'm building a RESTful API in Rails 4, and having a difficult time with getting Rails to send nested form attributes for a has_one association through to the database. I believe that my models are set up as they should be: class User <…
0
votes
1 answer

How can I treat a model in ActiveModel like a hash?

I'd like to create a Settings model centered around a "settings" database table in my Ruby app. The table looks like this: ========================== id | key | value ========================== 1 | site_version | 1.0.5 2 | something …
Chad Johnson
  • 21,215
  • 34
  • 109
  • 207
0
votes
1 answer

Propagating Model#save across all ActiveModel associations

I have the following: class User < ActiveRecord::Base has_one :blog end class Blog < ActiveRecord::Base belongs_to :user end If I do this: @user = User.new @blog = Blog.new @blog.title = 'hi' @user.blog = @blog @user.save Why/how is it…
user3621156
  • 65
  • 1
  • 7
0
votes
1 answer

Undefined method 'where'

I have this: def self.testing nodo = Attribute.where(:product_attribute_type_id => 7, :value => 1) end in a Product class method, then I load Attribute Class before a load Product class, then I call the testing method: a =…
José Castro
  • 3,976
  • 2
  • 22
  • 26
0
votes
0 answers

FormObject validation

I have form object which is responsible for searching proper cars. class SearchForm include Virtus.model include ActiveModel::Naming include ActiveModel::Validations include ActiveModel::Conversion include ActiveModel::Model validates…
Mateusz Urbański
  • 7,352
  • 15
  • 68
  • 133
0
votes
1 answer

Check validates_uniqueness_of in rails for two values in or condtion

i'm having problem in checking validates_uniqueness_of which has two condtion. Class name is InviteGuest class InviteGuest < ActiveRecord::Base attr_accessible :invite_id, :email, :first_name, :last_name, :random_no validates_presence_of…
0
votes
0 answers

PGError "column doesnt exist" with default_scope in Rails 3

I have a rails 2.3.8 application which I migrated to rails 3.0.10 However after migration, I could see issues using default_scope in the models. I am baffled why it is coming , though everything worked fine previously .I am using pg 0.11 gem . In…
Gaurav
  • 111
  • 8
0
votes
1 answer

establish_connection when accessing model or table

I'm trying to connect to 2 databases in my Rails application. I created 2 models in my RoR app which is for 2 tables on 2 different databases. I know how to connect to the other database before accessing the table…
0
votes
2 answers

undefined method error for instance variables in rails4 app

I was practising one of tutorials from a book. In this tutorial; all values from a few models were needed to be shown in some views. These instance variables were defined under sidebar_values method in application_controller.rb: helper_method…
ekremkaraca
  • 1,453
  • 2
  • 18
  • 37
0
votes
1 answer

Why does has_many through touch: true work like this with a self-referential model?

I have a self-referential relationship and a has_many_through association set up with a model called "Item". I'm using touch on the "join model". My issue is that when I "tag" a child object, the parent isn't "touched" even though there is a touch…
Julian Leviston
  • 1,646
  • 10
  • 21
0
votes
0 answers

Forms for nested ids

I have a model that I can update through the form instance.update(some_relations: [ {id: 1, some_other_relation_id: 26}]) This works great. The some_relation with id 1's some_other_relation is updated to point to 26. However I have no idea how to…
Beau Trepp
  • 2,610
  • 4
  • 22
  • 30
0
votes
1 answer

How to perform #find on an object without Active Model

Here's what's happend: I have gone and pulled a large amount of data from an API. This is nice, but it includes a lot of results. When I do a result.find(id: api_id) I get all the results like find was never performed. #where does not work either.…
BenMorganIO
  • 2,036
  • 17
  • 37
0
votes
1 answer

How to use ActiveModel callbacks on class methods?

I want to execute a method before each class method. Is it possible to do this using ActiveModel callbacks or do i have to use metaprogramming ? I tried : class Image extend ActiveModel::Callbacks define_model_callbacks :create before_create…
vdaubry
  • 11,369
  • 7
  • 54
  • 76
0
votes
1 answer

Custom Validation Message not found

I have a weird problem with Error Messages. This is my class only Virtus and ActiveModel Validations. I have some validations in there. Locally on my machine everything works fine. But on the server the custom messages like…
michael_knight
  • 4,921
  • 3
  • 17
  • 10