Questions tagged [virtual-attribute]

113 questions
0
votes
1 answer

Combining virtual attributes to single class attributes in super class (STI)

I'm trying to combine start_date, start hour, and start_minute virtual attributes from my Event form, in order to create a start_datetime attribute (which is stored in the database). I have (via STI) several subclasses of Event; let's call them…
0
votes
2 answers

Rails 4: language select and virtual attributes

I'd like to have a small dropdown menu where users can select the website's language. For that, I have <%= f.select(:lang, options_for_select([%w(中文 ch), %w(English en), %w(日本語 jp), %w(한국어 kr)], 'en')) %> I'd like this to appear on all pages, and I…
DaniG2k
  • 4,772
  • 36
  • 77
0
votes
2 answers

Rails 4: Password Validation Error: "{:password=>["can't be blank"]}" even though form is filled out

I'm relatively new to Rails (using Rails 4), and am having a problem with validation for my user model. Even when the form is fully filled in with both the passwords, when I submit the code two errors print out: {:password=>["can't be blank"],…
0
votes
1 answer

Assigning Virtual Attribute in Rails

I'm attempting to understand the difference between these two ways of assigning virtual attributes in Rails 4. One of them causes a "stack level too deep" and one of them works fine. I'm attempting to use the new ActiveRecord array field by parsing…
user449511
  • 249
  • 6
  • 14
0
votes
2 answers

Converting Rails attributes to property-value pairs

I have a Media model that has a bunch of standard metadata attributes and is persisted in the database as normal. What I want to do now is to add some configurable metadata attributes to this model on top of the existing attributes. A list of these…
richard
  • 1,565
  • 2
  • 18
  • 35
0
votes
1 answer

Assigning multiple form values to one database column

I am newbie to Rails and I cannot seem to find how to assign multiple form values from my view to a single Database column (model attribute). So I tried the virtual attribute approach, here is my code: My View: <%= form_for @userinfo do |f|%> <%=…
av85
  • 3
  • 1
0
votes
1 answer

Defining a virtual attribute in Rails and making it available as a symbol

I've defined a couple of virtual attributes, defining both the setter and the getters methods: class Post < ActiveRecord::Base def shared_to_all # evaluates some expression of the attribute privacy end def shared_to_friends #…
0
votes
2 answers

how to fill virtual form fields with non-split attribue

I have a form with 3 virtual attributes (phoneAreaCode, phonePrefix and phoneSuffix) splitting a phone number into segments which gets joined together and saved to the database as phoneNum. When a user goes to update their profile, most of the…
gr0k
  • 789
  • 2
  • 9
  • 22
0
votes
1 answer

Rails Getting a running balance with ordered list - summation virtual attribute

I'm trying to get a current balance per transaction, a simple summation (Credit's up to record - Debits up to record) on an ordered list. The challenge is that transactions are often entered out of order, and the transaction logs are sorted by a…
0
votes
1 answer

Rails 3: virtual attribute not being set

I have the following User model with a artist_attributes virtual attribute: class User < ActiveRecord::Base attr_accessor :artist_attributes attr_accessible :artist_attributes belongs_to :artist accepts_nested_attributes_for :artist,…
Robert Audi
  • 8,019
  • 9
  • 45
  • 67
0
votes
1 answer

Mongoid spacial virtual attribute does not persist

I am using Mongoid Spacial to store coordinates on a Place model. I am geocoding on the client side, and sending two text fields: latitude and longitude. The fields are named correctly, and this appears to be a server-side issue because the…
0
votes
1 answer

UnknownAttributeError using build for virtual attribute

I have a nested form containing virtual attributes :card_number and :card_verification. When I try to build with these in the controller update action, I get ActiveRecord::UnknownAttributeError. The models have a simple has_one relationship, where…
Tyler
  • 11,272
  • 9
  • 65
  • 105
0
votes
1 answer

Virtual attributes with multiple parameters

I have the following function that works just fine def holiday_hours_for(holiday) hours["holiday_hours"][holiday.to_s] if hours["holiday_hours"][holiday.to_s] end I am just learning about virtual attributes, and am having some trouble figuring…
Brandon
  • 1,735
  • 2
  • 22
  • 37
0
votes
1 answer

insert reblogged articles in the right place in blog.articles array ordered by created_at

EDIT: Actually I just decided against my way of reblogging and instead decided to implement it by copying and making a whole new record from the article and then add a reblogged: true column to it. A bit cleaner in logic in my opinion and it avoids…
0
votes
3 answers

Virtual attributes in plugin

I need some help with virtual attributes. This code works fine but how do I use it inside a plugin. The goal is to add this methods to all classes that uses the plugin. class Article < ActiveRecord::Base attr_accessor :title, :permalink def…