I have an Adult model with a name attribute.
If the user is logged in, I want the name Adult.name to return only the first name.
Is there a way to bind helpers to a model where you can specify Adult.helper.name?
Or at least there are helpers placed in the model?
Just explicitly include the helper in your model
# app/helpers/adults_helper.rb module AdultsHelper def say_hello "hello, world!" end end # app/models/adult.rb class Adult < ActiveRecord::Base include AdultsHelper end
Console Testing
$ script/console >> a = Adult.new # => #<Adult id:...> >> a.say_hello # => "hello, world!"
in the Adult model you can add
def name self.first_name end
so when you find adult for example
a = Adult.last puts a.name #will print a.first_name
Ok for a better explanation .. paste the code!
Source: https://habr.com/ru/post/893520/More articles:Use Rails Helper in Model - ruby | fooobar.comLINQ - how to get the next three business days excluding dates in the table? - linqBean start not called - java-eeXcode - How could you copy paste classes / files from one project to another? - xcodeSDL / OpenGL: implementation of the "boot stream" - c ++Problems with Object.toString in IE8, backbone.js - javascriptPython-Oracle passing in Cursor Out parameter - pythonDisplay dynamic text in Android view - javahttps://translate.googleusercontent.com/translate_c?depth=1&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/893524/what-happens-to-objects-passed-between-dependent-phpunit-tests&usg=ALkJrhid8KgltSz2yRB1XFk2gMtdioecMwCreate a new branch from the master, and then bring the master back to a specific commit - gitAll Articles