In my model, I have a method that returns a variable.
def do_something(param1, param2)
#code
return variable
end
I successfully call this method from a partial rendered in my show page. Like this:
<%= @user.do_something(param1, param2) %>
I want to call the same method from a partial rendered in my index page. But I’m running into errors. edit: an undefined method for class error.
I could copy and paste all my method code into a duplicative method like:
def self.do_something(param1, param2)
#code
return variable
end
and call it from the index page partial like this…
<%= User.do_something(param1, param2) %>
… but that’s not DRY, and I know there’s probably a more appropriate solution out there. I’m still learning rails mechanics, so I appreciate your help.
At least you can use delegation: