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

ActiveModel::Serializers with nested objects

I'm working on the rails API application which is using ActiveModel::Serializers. The problem I faced is that I'm not able to create a single response format for all calls with usage of ActiveModel::Serializers. I tried several approach. One of them…
Tomasz Dubik
  • 641
  • 4
  • 6
0
votes
1 answer

Rails: "_changed?" for values of relationship

In my project I have User objects which have multiple Order objects. Now on my form a user can edit his credentials and can deactivate the assigend orders: Orderform: - Firstname - Lastname - Email - Subform Orders: - Order1 - active - Order…
Besi
  • 22,579
  • 24
  • 131
  • 223
0
votes
1 answer

model without database: uninitialized constant

I'm quiet new in ruby on rails. I'm trying to develop an app which uses ActiveModel objects only in controllers without saving. Unfortunately after clicking the submit button I get an error. The aim of this app is to perform some calculations and…
0
votes
1 answer

Rails model behavior involving current_user

Say I have three models: Post has_many :comment has_many :user, through post_user Comment belongs_to Post User has_many :post, through post_user A logged in user can create/edit ANY post or comment. Whenever a user create/edits a post or a…
skalb
  • 5,357
  • 3
  • 26
  • 23
0
votes
2 answers

How to send the ID of a specific object (associated models) with a form?

I have 2 associated models (items and cities - cities is already populated by me) and a form where users can enter things they notice in a city. They can now enter the name of that thing and the ID of the city. However, obviously I would like to let…
watt
  • 799
  • 3
  • 8
  • 22
0
votes
2 answers

Format xml with properties with acts_as_api

i have a doubt with acts_as_api. i want to format a xml string like this: Some Text etc this is possible? thank's in advance
Andrea Mucci
  • 747
  • 2
  • 9
  • 25
0
votes
1 answer

Rails4 activemodel validations on concerns

I've got below code in my model which I want to use for validation: class Payslip < ActiveRecord::Base include ActiveModel::Validations attr_accessor :first_name, :last_name, :annual_salary, :super, :payment_start_date validates…
Passionate Engineer
  • 10,034
  • 26
  • 96
  • 168
0
votes
0 answers

Adding an error to an attribute in Rails

I use errors.add(:body, 'is a bit short.. ') which will result in the error message Body is a bit short I'd like to add an error to :body but with the result Explanation is a bit short Is there a way to change beginning of the error message and…
Nick Ginanto
  • 31,090
  • 47
  • 134
  • 244
0
votes
1 answer

Is it necessary to put column:string on rails 3/4 generate model?

I saw in a post that was not necessary to specify the type string for some column. But it didn't say which Rails he was using and the ruby guide put the :string anyway. In which version is that required ?
Cassio Cabral
  • 2,652
  • 3
  • 23
  • 37
0
votes
1 answer

I don't know how to keep it dirty ('it' is an ActiveRecord model btw)

Check this out: it "should not be this tough" do was = obj.association_id expect(obj.association_id).to eq 1 obj.association_id = 2 * was expect(obj.association_id).to eq 2 expect(obj.association_id_changed?).to be_true …
bgates
  • 2,333
  • 1
  • 18
  • 12
0
votes
1 answer

how to avoid repetition with identical models in rails

In my project I have two models which have identical attributes, methods and everything the same. at the moment they are in app/models/ in separate rb files, with quite some repetition of code. I would like to export all that code to a separate…
Don Giulio
  • 2,946
  • 3
  • 43
  • 82
0
votes
1 answer

Create has one polymorphic association

In my Rails 4 Application, my Developer model has one user, eg: class Developer < ActiveRecord::Base has_one :user, as: :account ... end And in my User model I have class User < ActiveRecord::Base belongs_to :account, polymorphic:…
ny95
  • 680
  • 5
  • 17
0
votes
0 answers

error with rails form and activemodel

I have some issues with a form that is not posting and there is nothing that is shown in the logs. I am not sure if the problem comes from activemodel, file name conventions, or or routing. No messages are sent. My controller is pretty basic it's…
Ayrad
  • 3,996
  • 8
  • 45
  • 86
0
votes
2 answers

Best way to do has_one and belongs_to_many?

I have a rails project similar to a blog with posts that have set of images and one featured image. The image set was a pretty straight forward HABTM relationship, as several posts can share the same image and one post can have many images, but the…
Dylan Karr
  • 3,304
  • 4
  • 19
  • 29
0
votes
1 answer

CanCan based access with multiple views

I'm working on a Rails 4 app and im trying to come up with a solution. I was wondering how i could implement CanCan to allow users to access certain data. Such as a guest can only view certain parts of the content. An owner can have full access to…