I am using a code where for updating fields i have to use different methods based on some condition. code snippet looks like
@issue = Issue.find(some_id) # Issue is ActiveRecord class
if 'class fields' # some condition checking
@issue.send("status").name = data # status is a class and name is its attribute
@issue.save
else
@issue.update_attribute("subject", data) # subject is a string
end
i am looking for a solution where i can use update_attribute to update class attributes
for e.g.
@issue.update_attribute(@issue.:status.name, data) # invalid
may be i am doing some thing silly
but i want to know a better approach
thnx.
You need use the
accepts_nested_attributes_for( system.In your Issue class your need define your status association like nested_attributes
After you can update your status by
PS : You can’t do it on belongs_to associations.