Menu
  • HOME
  • TAGS

Treating the file store as a column in the table

ruby-on-rails,virtual-attribute

I think it might be better to use before_save and after_find callbacks here. Add accessors to the class to allow the attributes to be stored in memory when creating/updating the content. Then when you save to the database, save the content to a file. When loading records from the database,...

How do I do where queries across virtual attributes?

ruby-on-rails,ruby-on-rails-4,activerecord,virtual-attribute

scope :with_tags, ->() { joins(:tags).uniq } You cannot use where as tags are stored in a separate table than your model - you have to make a join with this other table first. Now the lovely part - joins executes the INNER JOIN which means it will not load models...

Virtual Attribute in Rails 4

ruby-on-rails,ruby,ruby-on-rails-4,virtual-attribute

Instead of using attr_accessor you could create custom getter/setters on your product model. Note that these are not backed by an regular instance attribute. Also you can add a validation on the supply association instead of your virtual attribute. class Product < ActiveRecord::Base belongs_to :supply ,dependent: :destroy validates_associated :supply, presence:true...

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

ruby-on-rails,forms,virtual-attribute

Simplest is to add in a before_save callback, we'll use the changed array to check whether any of the attributes we're interested in have changed before we do our lookup: before_save :set_address def set_address if address = Address.find_or_create_by( city: city, zip: zip, street: street, suite: suite) self.address = address end...

rails simple_form using virtual attributes

ruby-on-rails-4,autocomplete,simple-form,model-associations,virtual-attribute

You are referencing an association that doesn't exist with f.association :head_coach_name. Try this instead: f.association :head_coach, label_method: :head_coach_name You have a few other oddities in your code, including your head_coach_name definition, which should rely on head_coach instead of user. Same concern for the head_coach_name= method. Example. You have: def head_coach_name...