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

Ruby on Rails search with multiple parameters

For example in my Car model i have such fields: color, price, year and in form partial i generate form with all this fields. But how to code such logic: user could enter color and year and i must find with this conditions, user could enter just…
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
0
votes
1 answer

Select 4 random rows from the first 20 rows

In my rails code I have: @vip_cars = Car.where(is_vip: true).order_by(created_at: :desc).limit(20) In this code I select some data and take the first 20 rows, but from those I want to select 4 rows, selected randomly. For example 4, 9, 1, 18 ? How…
brabertaser19
  • 5,678
  • 16
  • 78
  • 184
0
votes
1 answer

Rails 4: Have a published and draft version of models with has_many associations?

I have thought hard on this, and searched a lot, but it seems there is not many people who have encountered this situation. With Rails 4, what is a straight forward way to have a published/draft setup with has_many associations and some degree of…
Dan
  • 173
  • 2
  • 8
0
votes
2 answers

Rails - Pass collection to ActiveModel object

I am using rails to make a datatable that paginates with Ajax, and I am following railscast #340 to do so. This episode makes use of a normal ActiveModel Class called ProductsDatatable or in my case OrdersDatatable to create and configure the table.…
Marco Prins
  • 7,189
  • 11
  • 41
  • 76
0
votes
2 answers

uninitialized constant ContactsController::ContactMailer

I am trying to use ActiveModel to create a contact us form. When I click submit i get a NameError uninitialized constant ContactsController::ContactMailer on line ContactMailer.new_contact(@contact).deliver Can someone show me what I am doing…
xps15z
  • 1,769
  • 1
  • 20
  • 38
0
votes
1 answer

rails 4 should i use call back filter or concerns for this

I want to store url's but extract the base url and store it in different table of its own. url: example.com/this-is-worth-saving base url: example.com URL table: +----+-----+-------------+ | id | url | base_url_id…
ArrC
  • 203
  • 1
  • 3
  • 11
0
votes
3 answers

rails view has_many relation

I have such two models: class Article < ActiveRecord::Base belongs_to :articles_type end class ArticlesType < ActiveRecord::Base has_many :articles end and in controller i write: @articles = Article.where(article_type_id: params[:id]) and…
Valdis Azamaris
  • 1,433
  • 5
  • 22
  • 47
0
votes
1 answer

validation fails on SecurePassword Virtual Attributes on custom create at Activerecord Model

I'm trying to mix a custom User authentication mechanism based on SecurePassword with Facebook integration through omniauth-facebook gem. my app uses Ruby 2.0.0 and Rails 4.0.0. i tried to follow this guide omniauth and some other articles to came…
rccursach
  • 305
  • 3
  • 14
0
votes
2 answers

What's the best way to make a db column case insensitive in Rails?

I'm working on an RoR project where I have a model with a string attribute that needs to be entirely case insensitive. I'm just wondering what the best way to do this is. I've seen some cases where people add setters to their models which uppercase…
Dylan Karr
  • 3,304
  • 4
  • 19
  • 29
0
votes
1 answer

Elasticsearch ActiveModel integration

The Tire gem has been retired and has been replaced by the new elasticsearch gem. The elasticsearch gem doesn't appear to include ActiveModel integration or will_paginate compatibility. Are there any gems out there that add this functionality on top…
balexand
  • 9,549
  • 7
  • 41
  • 36
0
votes
1 answer

Adding or updating record with user id

Ruby on Rails 3, I have an edit page with two select_tag submissions. One has users that have the attribute :attend = "Yes" and the other has users that have the attribute :attend = "No" or nil. I am trying to get the select_tag submissions to…
DDDD
  • 3,790
  • 5
  • 33
  • 55
0
votes
1 answer

Setter but no getter for referenced attribute with Mongoid+ActiveModel

I have an Invoice (belongs_to :contact) and a Contact (has_many :invoices). In a new invoice form I want to reference which contact it belongs to. For that purpose, the following field: Which works when I…
Jacob U
  • 35
  • 3
0
votes
1 answer

Serializing models and resolving references with spira/RDF.rb

I'm using Spira as a model/persistence layer for a Ruby application. I'm having trouble getting a suitable serialization (e.g., as RDF/XML) for my individual models. For example, when I dump a model that contains "associations", I get XML that…
Jacob Brown
  • 7,221
  • 4
  • 30
  • 50
0
votes
1 answer

How to define models and associations in this scenario?

Supposed I have a model Relleno(relleno_id, descripcion) with records: (1, Activo) (2, Inactivo) (3, DNI) (4, LC) (5, LE) Then, I want to connect 2 entities with this model: Chofer(nombre, estado) and Cliente(modelo, tipdoc), where Chofer.estado…
eKek0
  • 23,005
  • 25
  • 91
  • 119
0
votes
0 answers

after_initialize for MongoMapper?

ActiveRecord has after_initialize, but ActiveModel does not. MongoMapper is built on ActiveModel. Is there a way to create an after_initialize callback for MongoMapper?
B Seven
  • 44,484
  • 66
  • 240
  • 385