So, as said it is a very wrong idea to store code in your database. There is very little exception to that and it's very complicated to implement, bug prone, and present security issues. In short: don't do it.
So you need an alternative design. There is basically 3 situations, pick-up the one that correspond to your application's goal:
A- If your method parameters and output will never change in the future, then you execute your code and store the output in a cached columns (type string or text) of your model before saving. When retrieving this cached output later you can just use it as it
post.cached_output = my_method(...)
post.save
# In the future, in your view:
<%= post.cached_output %>
B- If the parameter of your method will never change in the future but the method output differs according to external elements, then just store that one parameter's value and call the method each time you need its output
post.cached_parameter = 17
post.save
# In the future, in your view:
<%= my_method(params: post.cached_parameter) %>
C- If your method's parameter change over time and your method output also changes overtime, then you don't need to cache anything in your database
evalon the string. However, if your intention is to render something that is specific to only one or a few objects, it would be far better and easier to build this in to the model, or view template itself.