Giter VIP home page Giter VIP logo

Comments (9)

johanbaaij avatar johanbaaij commented on June 1, 2024 1

Hi, i'm trying the following:

app/cells/main_menu_cell.rb

class MainMenuCell < Cell::Rails
    include Devise::Controllers::Helpers
    helper_method :current_user

    def display
        render
    end
end

display.html.haml

- if user_signed_in?
    %li
        = link_to 'Logout', destroy_user_session_path, :method=>'delete'
- else
    %li
        = link_to 'Login', new_user_session_path

But i'm getting a undefined method `user_signed_in?'

What could I be doing wrong?
Cheers!

Edit:

duh. I get it :). Had to use
helper_method :user_signed_in?

from cells.

mixr avatar mixr commented on June 1, 2024

i have the same problems in a rails 3 app and just use signed_in?(:user) for the moment.

when i tried to reproduce the problem in a blank rails 3 app, everything worked fine just by including "include Devise::Controllers::Helpers" in the Cell.

i have no idea right now which part of my app-setup is responsible for this.

from cells.

bhavinkamani avatar bhavinkamani commented on June 1, 2024

Thanks for your inputs. While signed_in?(:user) seems to be working fine. I am getting stuck with resource_name while inserting login form inside cell view. I have included Devise::Controllers::Helpers in the cell. I am trying to keep the view code as close to devise generated view code as possible. Hence I am not directly using user model.

Did you happen to face that problem?

from cells.

bhavinkamani avatar bhavinkamani commented on June 1, 2024

Apart from "include Devise::Controllers::Helpers", inserting Devise::Controllers::Helpers.define_helpers(User) helps me access rest of the devise helper methods. Not sure if this is the best way or the cleaner way to access devise helper methods.

from cells.

apotonick avatar apotonick commented on June 1, 2024

I got it working by calling

helper_method :current_user

and that's what José recommended, too!

from cells.

bhavinkamani avatar bhavinkamani commented on June 1, 2024

Thanks it works great... looks much cleaner too..

from cells.

mixr avatar mixr commented on June 1, 2024

hey,

did you try with a fresh rails 3 app? it's working without any extras, just include
include Devise::Controllers::Helpers
you can try the example app here: https://github.com/mixr/cells_devise

from cells.

bhavinkamani avatar bhavinkamani commented on June 1, 2024

Hi,

Yep I tried and yes it indeed works without any additional line... Its kind of strange because now when I run my app after removing "helper_method :current_user" its recognizing user_signed_in? method. I have still not figured out why it was giving me error earlier. But good news is that it now works with one line code and thats 50% improvement over 2 lines :-) Thanks a ton.

from cells.

fsmanuel avatar fsmanuel commented on June 1, 2024

thax!
class TransactionWidget < Apotomo::Widget
include Devise::Controllers::Helpers

helper_method :current_user

did the trick!

from cells.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.