In my application, I have a Widget model, a Feature model with has_many association through the WidgetFeature table.
As required, when I submit a WidgetFeature object, I have to add the file_name to it for this related function.
There are two ways in it:
- When sending an object, do the following:
widget_feature_object[:feature_name] = feature_name_value
and then I can access it in my controller or in the view, widget_feature_object[:feature_name] , because the object has pairs (key, value), so I can add another.
2. Create feature_name a Virtual attribute in the WidgetFeature model, and then create retrieval and configuration methods for it.
From what I know, you should use virtual attributes if you want to create a different view than the fields actually present in the model (for example, Full Name = First Name and Last Name).
Does the same thing apply here?
Also , does Rails do some object caching, which might come in handy when using virtual attributes rather than the first time?
What are the pros and cons of each approach and which one is best suited to my requirements? Thank you very much.
source share