Questions tagged [virtual-attribute]

113 questions
0
votes
1 answer

How can I get a unique :group of a virtual attribute in rails?

I have several similar models ContactEmail, ContactLetter, etcetera. Each one belongs_to a Contact Each contact belongs_to a Company So, what I did was create a virtual attribute for ContactEmail: def company_name contact =…
Satchel
  • 16,414
  • 23
  • 106
  • 192
0
votes
1 answer

Rails 4 Minitest Testing Virtual Attributes

So I have a class TimeBank, and its being updated, and is getting two new virtual attributes which will manipulate two other existing attributes (DB columns). class TimeBank < ActiveRecord::Base # validations, consts, few other methods omitted for…
Todd
  • 2,824
  • 2
  • 29
  • 39
0
votes
1 answer

Virtual attributes in nested forms are not recorded

You'll see in my code I've got a "has_many => belongs_to" models association and a nested form in the new actions's view. Plus, I've used Using two separate fields for the same parameter in a Rails form handler? The problem is the "prix" attribute…
Hugololo
  • 3
  • 2
0
votes
1 answer

How do I do where queries across virtual attributes?

I have a Node model, that has a virtual attribute user_tags. This is what it looks like at the console: [42] pry(main)> n = Node.first Node Load (0.5ms) SELECT "nodes".* FROM "nodes" ORDER BY "nodes"."id" ASC LIMIT 1 => #
marcamillion
  • 32,933
  • 55
  • 189
  • 380
0
votes
1 answer

use multiple virtual attribute form inputs to update a single model attribute

I have the following virtual attributes within my model: attr_accessor :city, :zip, :street, :suite In the new/edit form, I have form fields for each of these attributes. I can convert these four attributes into a single address_id with a method…
Tim Koelkebeck
  • 795
  • 2
  • 9
  • 18
0
votes
1 answer

How to create read-only virtual attributes in Ruby models

I would like to create a virtual attribute that will always be included when you do model_instance.inspect. I understand that attr_reader will give me the same thing as just defining an instance method, but I would like this attribute to be part of…
Bill Brasky
  • 201
  • 1
  • 3
  • 13
0
votes
1 answer

Yii virtual attribute and models

Can a virtual attribute represent a model ? I've read this wiki but don't find answer. Edit : The aim is to make my model more explicit for the user. abstract class BaseDonnee{ protected $info; public function representingColumn(){ …
sk001
  • 561
  • 6
  • 27
0
votes
0 answers

Trouble with virtual attribute for payments

Im currently trying to convert my price_in_cents field to the virtual attribute of price_in_dollars. I did some research and basically implemented everything from the railscast virtual attributes video, here is the link…
0
votes
2 answers

Preference values - static without tables using a model with virtual attributes

Im trying to eliminate two tables from my database. The tables are message_sort_options and per_page_options. These tables basically just have 5 records which are options a user can set as their preference in a preferences table. The preferences…
Michael
  • 1,032
  • 2
  • 15
  • 31
0
votes
2 answers

Rails 3 - Validating against virtual attribute results in Exception

I have a virtual attribute, called currentBalance, in one of my models. An ajax call in my view populates this attribute. In the model I'm trying to validate that the net_weight is less than or equal to the currentBalance which represents total net…
0
votes
3 answers

Why are my virtual attributes not working?

I'm using Rails 3.2.17 trying to access two virtual attributes (expiration_amount & expiration_format) in a model but nothing I've tried allows me to access them. Everything else seems to update correctly, however in my logs the virtual attributes…
Eric Norcross
  • 4,177
  • 4
  • 28
  • 53
0
votes
1 answer

Virtual attributes on new models in Rails?

This certain part of my application takes cares of creation of Webshop model for store chains (like H&M) that has one. If the chain has a website that also is a webshop it creates one Webshop model. If the website is not a webshop then it lets it be…
Antony Sastre
  • 617
  • 8
  • 19
0
votes
1 answer

Rails 3.2, virtual accessor and deprecation warning

I'm really confused about virtual attributes in Rails 3.2 and all my research haven't help making things clearer. # input model class Input < ActiveRecord::Base # Attributes -------------------- attr_accessible :title, :parent attr_accessor…
karellm
  • 1,843
  • 1
  • 20
  • 23
0
votes
1 answer

Rails Virtual Attribute(s) Not Validating

I guess that in many ways I'm still a newbie with some of this rails stuff. I have ActiveRecord Model for Payments. But, it only has two things that get added to it's table and those are done once we get a positive response back from authorize.net.…
Drew Harris
  • 486
  • 1
  • 5
  • 13
0
votes
1 answer

Virtual attribute in a Rails app - why is attr_writer not making my input work with my getter and setter methods?

I'm trying to roll my own tagging system. My setup is (at the moment) much like acts_as_taggable_on, with Tags, Taggable objects, and Taggings to relate the one to the other. Taggable is a module, which will be included in Events, Users, and…