Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using #dom_id(obj) within controller to set variable

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

like image 772
Neil Avatar asked Dec 15 '22 02:12

Neil


1 Answers

Inside your conroller, Try to add

class YourController    
include ActionView::RecordIdentifier
...

end
like image 137
Abdoo Dev Avatar answered Dec 27 '22 01:12

Abdoo Dev