I'm trying to get my head around Rails and ActiveAdmin, and string representations of objects. Particularly, I'm struggling to define a single method that'll get picked up by Rails (in the templates) and ActiveAdmin.
If I do something like:
def to_s
"Hello world"
end
Then that works in Rails. But not in ActiveAdmin, which only picks it up if I use display_name
. It's solved by doing this:
alias_attribute :to_s, :display_name
But is that a bit hacky? Just wondering if I've missed something obvious. Thanks!
In the end, I used:
def display_name
"#{name}"
end
What about calling the method something else like
def something
"Hello World"
end
and then calling...
alias_attribute :something
Perhaps there is a conflict with calling the method to_s in this case?
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.