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

Rails has_and_belongs_to_many with Many

I'm working on a Rails 4 app with complex associations and i cant figure out how to join one model to a parent. Basically my apps logic is as follows User - belongs_to :account, polymorphic: true Developer - has_one :user, as: :account -…
ny95
  • 680
  • 5
  • 17
0
votes
1 answer

Rails Relation Table

so i'm working on a rails 4 app and i have two models a Developer and an App. Basically i want a Developer to act as a founder and have multiple Apps and those apps belong to the Developer (founder). Then i want and app to have many collaborators…
ny95
  • 680
  • 5
  • 17
0
votes
3 answers

Rails associations in one table (belongs_to :region, has_many :regions)

I'm trying to create simple geo-model with tree-structure with Rails4. Every region has one parent region and can have many children regions. class Region < ActiveRecord::Base has_many :regions, belongs_to :region, dependent:…
Pavel Tkackenko
  • 963
  • 7
  • 20
0
votes
1 answer

Setting One to One

I have a Rails 4 app which has a Devise user. The Devise user can create multiple Apps and each App can contain multiple Certificates. At any given time tho and App can only have one production_certificate and one development_certificate. I believe…
ny95
  • 680
  • 5
  • 17
0
votes
1 answer

DRY way to handle users with multiple accounts in Rails app

This is a Rails app for a school. I'm using Devise for user accounts. So far each user has a .role of admin, teacher or student which restricts what the user can access and contribute in the app. I'm using user.email to log in. All is working great…
Dan Weaver
  • 711
  • 8
  • 20
0
votes
3 answers

Whether to use has_many or has_many :through in a data model

I am using Ruby on Rails to build a web app, and my data model has users, and each user can create keys (musical keys, e.g. A# minor). Keys are made up of chords, and chords are made up of notes. There are a finite number of notes, but there are an…
jackerman09
  • 2,492
  • 5
  • 29
  • 46
0
votes
1 answer

Persistence functionality for ActiveModel

I have a class Document that inherits from another class MyGem::Record. I am "mixing in" ActiveModel functionality so that instances look like ActiveRecord objects. I am not inheriting from ActiveRecord::Base because I am already inheriting from…
Jacob Brown
  • 7,221
  • 4
  • 30
  • 50
0
votes
2 answers

Rails relationships with foreign key between?

I have two entities in my Rails app for which I'm trying to establish a relationship - checks and months. Instances of Month will have a start_date and an end_date - these dates do not exactly align to the calendar month. Instances of Check will…
user1706938
  • 131
  • 1
  • 9
0
votes
2 answers

ActionMailer and ActiveModel

I'm trying to make a simple contact us form so I need to implement the mailer. I created a controller: class ContactusController < ApplicationController def index @contact_us = Contactus.new end def new redirect_to(action:…
Dinkar Thakur
  • 3,025
  • 5
  • 23
  • 35
0
votes
1 answer

Wrong Number of Arguments Error with ActiveRecord New

I have a ActiveRecord::Base subclass. When I create a new instance I'm getting an argument error: ArgumentError: wrong number of arguments (2 for 1) Here is my code: class Subclass < ActiveRecord::Base end Subclass.new(hash,…
Undistraction
  • 42,754
  • 56
  • 195
  • 331
0
votes
1 answer

How can I select desired columns without getting ActiveModel::MissingAttributeError?

I am trying to retrieve 2 columns from a mysql database to use with FullCalendar, using Ruby but I keep getting the ActiveModel::MissingAttributeError. What is the correct way of doing this? I have tried the following and checked SO but no luck.…
0
votes
2 answers

Validation association not working

I have two models: Location and User. Location has_many :users and User belongs_to :location. Now I have a form that uses something similar to: <%= form_for @user do |f| %> ... <%=…
Travis Pessetto
  • 3,260
  • 4
  • 27
  • 55
0
votes
1 answer

Displaying a tableless model in a view using ActiveModel:Model

I'm using Rails 4 and ActiveModel:Model for an app that will do a calculation and display the result to the user. I don't want to save the calculations to a database as they will only be used once and discarded. However, I don't know how to display…
Chris Lawrence
  • 281
  • 1
  • 4
  • 7
0
votes
2 answers

ActiveModel::MassAssignmentSecurity::Error (backbone.js + rails + rails-backbone gem)

I am trying to continue along the path I was lead down in this post: render show page on submit backbone.js + rails + rails-backbone gem I am still trying to figure out what I describe in the first paragraph of that question. I was messing around in…
ewizard
  • 2,801
  • 4
  • 52
  • 110
0
votes
1 answer

Allow blank dates to pass validation and save in the database?

I have a Rails app, I am using Mongoid driver to map to my Mongodb database. I would like to allow users to not specify their date of birth if they do not want to. If they do specify the date I would like the validation of the applicable years to…
General_9
  • 2,249
  • 4
  • 28
  • 46