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

rails model name single alphabet error

Whats up with this model names in rails ?, Why is this not working ? rails g model a_b_c name:text rake db:migrate rails c ABC NameError: uninitialized constant ABC Now, any sane person would ask me, why I would create a model a_b_c?.…
beck03076
  • 3,268
  • 2
  • 27
  • 37
-1
votes
1 answer

Equivalent RoR code for MySQL code

Sometimes ago I created database and a table in MySQL with these statements : CREATE DATABASE amiref; USE amiref; CREATE TABLE refoo ( f1 VARCHAR(20) , f2 VARCHAR(30) NOT NULL , f3 INT , PRIMARY KEY(f1) ); CREATE TABLE IF NOT EXISTS users ( …
-1
votes
1 answer

"ActiveModel::ForbiddenAttributesError " on Rails App ( 5) with nested attributes

I have a simple_form_for that creates an invoice. Through this form, I want the user to be able to create a client that will be associated with that before-mentionned invoice. The current process being to firstly create the client, then associate it…
-1
votes
1 answer

How to create 3 models in Rails 5 that are joined?

I'm looking to create the following models in Rails 5: Industry Department JobTitle Example Data: Industry: Technology, Healthcare, Other Department: Admin, Customer Support JobTitle: Account Manager, Accountant Industry is the highest-level,…
AnApprentice
  • 108,152
  • 195
  • 629
  • 1,012
-1
votes
1 answer

Unrelated rspec tests fail after adding active_model_serializers

I'm super confused. I think I'm encountering some kind of bug. Could use some help. I had passing specs (passed dozens of times on local and CI server), and these were completely unrelated to serializers. Like they _just check the status of certain…
-1
votes
3 answers

Rails 5 model with Nokogri gem return nil

I have problem with my app in Rails 5. I create class scrape.rb which scraping HTML via Nokogiri gem and can save this data in another model, but when I create new object in rails console this return nil and don't scrap any value: 2.3.0 :018 > s =…
-1
votes
1 answer

Rails 4: undefined method `facebook_copy_link' for LinkValidator

In my Rails 4, I have a Post model I need to implement a custom validation on. Following the recommendation in this question and in the documentation here, I have implemented the following code: #app/validators/link_validator.rb class LinkValidator…
Thibaud Clement
  • 6,607
  • 10
  • 50
  • 103
-1
votes
1 answer

NULL values in database on create action

When i clicked to submit, the parameters is shown with all the data, however, when i save it, it shows as: SQL (1.0ms) INSERT INTO `billings` (`birth`, `city`, `country`, `created_at`, `gender`, `ictype`, `idno`, `marital`, `name`, `national`,…
-1
votes
3 answers

How do I validate float values so that nothing but a float can be saved before submitting a form in ruby on rails 4?

I need a way to only allow values like: Ok: 23.55, 232.43, 300.34 2.34 Not ok: 23.4, 43.344, 343.454, 230, 34 I have a regex in my model but it seems to allow me to save values like 200, 344, 23. I need to restrict things so that I'm only allowed…
LondonGuy
  • 10,778
  • 11
  • 79
  • 151
-1
votes
1 answer

transfer associations from new object to existing object while preventing creation of new object

versions rails: (4.0.0) ruby: (2.0.0) mongoid (4.0.0) activemodel (~> 4.0.0) moped (~> 2.0.beta5) problem I have an interface where I create a book by submitting an ISBN and a list of authors. My aim is to avoid duplicate book records, and to…
-1
votes
1 answer

Field for Validator

If I have some CustomValidator, and following validation in model validates :fieldname, :custom => true How can I access :fieldname or true? Validator only takes object (def validate(record)) and I can't use EachValidator.
Wojtek
  • 239
  • 1
  • 2
  • 12
-1
votes
2 answers

Ruby ActiveModel not raising error

I'm trying to get error for my unit testing with R-Spec but this isn't working. I have below code using active model to validate max and min values as per below: require 'active_model' class Board < Struct.new(:width, :height) include…
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
-2
votes
2 answers

How to map an attribute into a list of objects in Rails?

I have four models. Event, Invitation, Profile and User. They have the following relations: Events have many Invitations Profiles have many Invitations Profiles belong to Users ...and in turn, Invitations obviously belong to both Events and…
zcserei
  • 577
  • 7
  • 30
-2
votes
3 answers

Rails form not saving city

I'm trying to create rails form for a customer. They should select a city for the list of existing cities. But it is not being saved. index.html.erb <%= form_for @customer do |f| %>
<%= f.label :first_name %>
<%=…
Antarr Byrd
  • 24,863
  • 33
  • 100
  • 188
-2
votes
1 answer

How come methods under 'private' and 'protected' can always be called in models (rails)?

I tested, that they, in fact, don't work: class User < ActiveRecord::Base def self.call_protected_method protected_method end def self.call_private_method private_method end protected def self.protected_method puts…
ExClouds
  • 527
  • 1
  • 7
  • 13
1 2 3
47
48