I want to use the method dom_id(arg)
within my controller. It has always worked in my views:
# in controller
@blog = Blog.first
# then in view
<%= dom_id(@blog)%>
=> "blog_1"
However: setting a variable via dom_id
does not work when doing it in the controller:
# ALL in controller
@blog = Blog.first
@dom_id_var = dom_id(@blog)
=> NoMethodError: undefined method `dom_id' for main:Object
Is it possible to use dom_id
within the controller?
Docs on dom_id
Inside your conroller, Try to add
class YourController
include ActionView::RecordIdentifier
...
end
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With