It seems that these helpers in app / helpers / foo.rb can be used in the view but cannot be used in the controller?
In some cases, different controllers may have to use the same method, but just pass a different parameter, so in this case it makes no sense to use an auxiliary element in the controller?
There are two main ways to reuse code between controllers.
ApplicationController, , , . ( ApplicationController , .)
ApplicationController
( ) , .
- , , - , , .
, . ( - , , )
ApplicationController, .
As mentioned above, you can put common helpers in an ApplicationController or subclass. I would add that in order to make them viewable, you added to the top of the class:
helper_method :foo
Source: https://habr.com/ru/post/1764981/More articles:JavaScript class methods do not work - javascriptЛучший способ обнаружить дубликаты загруженных файлов в среде Java? - javaHow do you determine the appropriate size when drawing a CheckBox? - checkboxHow can I automatically track PayPal donations and display them on my site? - javascriptPointer to a C ++ string - c ++What are the ASP.NET MVC conventions? - asp.net-mvcCorrect conditional statement behavior in VS2010? - c ++Android HelloViews Spinner Tutorial R.id and R.array cannot be resolved - androidUnicode column filtering on Sql 2005 server - for data mapping - sqlPython vs C: Line Comparison of Codes Against Time Dev - cAll Articles