Questions tagged [dynamic-attributes]
32 questions
210
votes
5 answers
Rails find_or_create_by more than one attribute?
There is a handy dynamic attribute in active-record called find_or_create_by:
Model.find_or_create_by_(: => "")
But what if I need to find_or_create by more than one attribute?
Say I have a model to handle a M:M relationship…

tybro0103
- 48,327
- 33
- 144
- 170
18
votes
1 answer
getattr() versus __dict__ lookup, which is faster?
I can dynamically look up object attribute values using object.__dict__[some_key] or getattr(object, some_key). Which is faster or better, and why?
>>> class SomeObject:
... pass
...
>>> so = SomeObject()
>>> so.name = 'an_object'
>>>…

Cole
- 2,489
- 1
- 29
- 48
15
votes
4 answers
Dynamic attributes with Rails and Mongoid
I'm learning MongoDB through the Mongoid Ruby gem with Rails (Rails 3 beta 3), and I'm trying to come up with a way to create dynamic attributes on a model based on fields from another model, which I thought a schema-less database would be a good…

joeellis
- 2,745
- 7
- 28
- 45
10
votes
3 answers
How to set a dynamic attribute
Is there a way to set col as dynamic or convert it in some way to a valid attribute?
It is currently throwing the error: undefined method `col=' for #...
def copy_stock_data_from_sandbox(cntrlr)
source_table =…

iamtoc
- 1,569
- 4
- 17
- 24
6
votes
2 answers
Using method missing in Rails
I have a model with several date attributes. I'd like to be able to set and get the values as strings. I over-rode one of the methods (bill_date) like so:
def bill_date_human
date = self.bill_date || Date.today
date.strftime('%b %d, %Y')
…

tybro0103
- 48,327
- 33
- 144
- 170
3
votes
2 answers
How Do I make dynamic-attributes Work in JSP Tag Files?
So according to my JSP reference book, as well as every other reference I can find on the web, I'm supposed to be able to do something like:
<%@ tag dynamic-attributes="dynamicAttributesVar" %>
and then when someone uses an attribute that I didn't…

machineghost
- 33,529
- 30
- 159
- 234
3
votes
1 answer
How to add conditional case sensitive attribute in Angular 2?
I want to add 'tourAnchor' attribute dynamically, for which I am adding below line.
But, the attribute is being replaced to case insensitive and upon condition check, it is being…

Rachitha B R
- 81
- 6
3
votes
4 answers
Remove image dynamically using jquery by clearing the src attribute
I know one can load image dynamically using
$("#id").attr("src","path of the image"),
but to onload the certain image on certain event,
$("id").attr("src","")
doesn't work.
What's the correct way to unload the image runtime using jquery??
I cannot…

Hazel
- 63
- 2
- 4
- 10
2
votes
1 answer
Unable to add a dynamic attribute to a Spring form:input tag
I have a Spring form tag and am trying to add a dynamic attribute (the "placeholder" attribute), but get the following error
org.apache.jasper.JasperException: /WEB-INF/jsp/work.jsp (line: 290, column: 3)
Attribute placeholder invalid for tag…

arnthorsnaer
- 53
- 2
- 7
2
votes
0 answers
JSP Custom Tag File and Dynamic attributes
I have a custom JSP tag tag file, which is a wrapper around HTML input controls - dropdown etc, like so -
Here "table" is a declared attribute of the tag where as…

Anupama
- 167
- 1
- 9
2
votes
2 answers
What is the purpose of dynamic fields in MongoDB?
At first, I thought it was pretty cool that you can add something to an object without it being defined in the model. But now I can't imagine how this is used in a web application like a Ruby on Rails application. What use cases require dynamic…

Jake Smith
- 2,332
- 1
- 30
- 68
1
vote
1 answer
Dynamically creating read-only attributes
I'm currently trying to create a class that inherits from set, but allows calling for subsets with attributes.
Since I want to create this class such that I can use it in any context, I want to have it be able to create attributes from any given…

JohnMcSwag
- 13
- 3
1
vote
1 answer
Add attributes inside custom attribute in c#
I want to dynamically add attributes to properties of a given class, because the project will get bigger and the procedure is totally repeatinglly, something like so :
public class MyAttr : Attribute {
public MyAttr () {
foreach(var prop…

Hooman Limouee
- 1,143
- 2
- 21
- 43
1
vote
0 answers
VBA to html, onclick event function with dynamic element attributes
I am trying to automate filling in a web form on intracompany web in excel using IE. My previous question was to target dynamic element ID which got resolved thank to
SIM (thanks again!)
Unfortunately I cannot use the same method to proceed; with…

Matus Kovac
- 19
- 2
1
vote
1 answer
Can't inflate view with dynamic attr drawable
I have ExpandableListView with custom adapter and in groupview of this list I use dynamic attrs for it's imagebutton src drawable, declared in such style:
g_view.xml
...
android:src="?attr/img_add"
...
attrs.xml
attr name="img_add"…

Movsar Bekaev
- 888
- 1
- 12
- 30