Rails with Cells and Helpers

1k Views Asked by At

I'm having trouble accessing the cookies object in my cell views via helper. My code looks like this:

#cell
helper SessionsHelper

#cell view
signed_in?

#sessions helper
signed_in?
    cookies.sth
end

I'm getting the error: undefined local variable or methodcookies'`.

How do I make cookies visible there?

Alternatively, I'd like to pass Helper as an object collaborator to my cell, because this helper contains a lot of useful methods. Is doing SessionHelper.new the correct way to do that?

<%= render_cell :my_cell, :display, session_helper: SessionsHelper.new %>

I now see that SessionsHelper is in fact a module, so I cannot invoke the new() method. What should I do with undefined cookies?

1

There are 1 best solutions below

0
On

I always define signed_in? in ApplicationController. (There cookies is available) And then do:

helper_method :signed_in?

to make it available as a helper method.

As for your second question: session_helper: SessionsHelper.new is not necessary. All methods from all helpers are available all views.