Rails Cells 4: access Devise helpers

719 Views Asked by At

I have a simple Cells example that I would like to integrate with Devise and Rails. However, all examples and questions seem to be for Cells 3. The following fails in my app (line numbers added).

line 1: class UserCell < Cell::ViewModel
line 2:   include Devise::Controllers::Helpers
line 3:
line 4:   def index
line 5:     render
line 6:   end
line 7: end

Raises this error for line 2.

undefined method `helper_method' for UserCell:Class
2

There are 2 best solutions below

0
On BEST ANSWER

Turns out that Cells is no longer configured to work the same way with Rails by default (via Cell::Rails). I had to add abstract controller helpers, but this got me all of the devise helpers in my cell automatically.

class UserCell < Cell::ViewModel
   include AbstractController::Helpers
   include Devise::Controllers::Helpers

   def index
     render
   end
 end
0
On

Another way to do it is to

def_delegator :current_user, :controller

You can delegate everything to controller

One more way, especially if you want to keep your cells and controller independent from each other, you can just pass objects and attributes to your cell in the options{} hash.