Questions tagged [virtual-attribute]
113 questions
2
votes
2 answers
Virtual attributes with Devise in Rails 4
My User model doesn't have a :name field but I want to include a :name field in my sign up form which will be used to create a record of another model in an after_create.
class User < ActiveRecord::Base
after_create :create_thing
private
def…

Aen Tan
- 3,305
- 6
- 32
- 52
2
votes
1 answer
CanCan, Rails 4, UnknownAttribute error on virtual attributes
I am having a heck of a time figuring out how to get a virtual attribute past CanCan during a new record create:
I have Teams, with :name and :description
Teams have users through memberships, which I control through a separate controller action,…

Merovian
- 58
- 5
2
votes
1 answer
Virtual Attributes with Sinatra and Datamapper
I am converting a Rails app to Sinatra. The application relied on ActiveRecord which supports virtual attributes, however, I am struggling to find similar support in DataMapper.
In Rails, I used an algorithm to generate scores and sort records…

Dru
- 9,632
- 13
- 49
- 68
1
vote
1 answer
Rails: Find or create by virtual attribute
I have kind of a tricky problem I'm working on in my current rails app. In my app users share photos. Photos can be associated with a city, so City has_many :photos. I want users to be able to associate their photos with a city using autocomplete…

Andrew
- 42,517
- 51
- 181
- 281
1
vote
1 answer
Rails 3 Nested Attributes?
I have an application that tracks services (servers) with IP addresses. I'm trying to set it up so that when I create a new service the following happens:
All IP addresses are looked up, if they do not have a service_id then they're classed as…

Paul Millar
- 184
- 7
1
vote
1 answer
rails virtual attributes won't read from form_for submission
I am trying to implement a rails tagging model as outlined in Ryan Bate's railscast #167. http://railscasts.com/episodes/167-more-on-virtual-attributes
This is a great system to use. However, I cannot get the form to submit the tag_names to the…

jay
- 12,066
- 16
- 64
- 103
1
vote
1 answer
Ruby on Rails - Searching virtual attributes (tags)
I've set up a Virtual Attribute tagging system as shown by Ryan Bates here: http://railscasts.com/episodes/167-more-on-virtual-attributes
The system works really well for applying tags to my models and is something I implemented into my system a…
anon
1
vote
1 answer
Setting model association in Rails - saving 'from grandchild side'
I'm a Ruby newbie so please forgive if some of these is complete ignorance. I want to set following associations:
Transcription belongs to Composition
Composition has many transcriptions, belongs to Artist
Artist has many compositions (and…

chodorowicz
- 1,062
- 1
- 15
- 19
1
vote
2 answers
How Do I Parse a Text Field and then Write it to Multiple Models in Ruby on Rails?
I have simple project+task application I am creating in Rails 3.1.RC4. It will have project names, tasks and each task will be assigned to a person. The project form is simple with only two boxes (1) task name and (2) the tasks and assignee. On the…

JHo
- 1,068
- 1
- 14
- 29
1
vote
1 answer
Rails Validating on a virtual attribute, setting form error. Railscast #32
I'm basically attempting to implement the solution from Railscast #32, modernized for Rails 3.0.7
http://railscasts.com/episodes/32-time-in-text-field
class Task < ActiveRecord::Base
attr_accessible :description, :complete, :deadline
validate…

Carl Thuringer
- 146
- 1
- 7
1
vote
1 answer
I have identical getter/setter code used for multiple virtual attributes - can I refactor with eval?
I have written customised getter and setter methods for virtual attributes to convert decimals into integers for storage in a database. This is one of three virtual attributes (annual_fee_dollars) that get/sets from a real attributes (annual_fee)…

Rob d'Apice
- 2,416
- 1
- 19
- 29
1
vote
2 answers
What's the best Rails convention for this?
Let's say that you have a resource that is created and displayed entirely within the view of another resource (eg. comments or tags). Should you still make it it's own resource, or would it be a better idea to make it a nested resource? Also, should…

Justin Meltzer
- 13,318
- 32
- 117
- 182
1
vote
1 answer
Yii2 call method/function of a different model
I have a method/function of a virtual attribute in Model1:
class Model1 {
public $virtattr;
public $_virtattr;
public function getVirtattr () {
if (isset($this->_virtattr)) {
return $this->_virtattr;
}
…

user2511599
- 796
- 1
- 13
- 38
1
vote
2 answers
Yii2 virtual attribute out of an attribute of a SqlDataProvider
My AddressController:
public function actionIndex() {
$searchModel = new AddressSearch;
$dataProvider = $searchModel->search($_GET);
return $this->render('index', [
'dataProvider' => $dataProvider,
'searchModel' =>…

user2511599
- 796
- 1
- 13
- 38
1
vote
1 answer
Using named scope with find_or_create_by
I spent some time figuring this out and haven't seen others post on it so maybe this will help someone. Also, I don't have much Rails experience so I'd be grateful for any corrections or suggestions, though the code below seems to work well.
I've…

NAD
- 615
- 1
- 7
- 20