The method
current_user like this
Now here helper_method create a method bye name of current_account and this is share for all controller which are inherited by #application_controller.rb.
NOTE : helper_method not accessible in model.rb . Helper method use in controller only for view and if we write a method in xxxx_helper.rb then this method is only accessible in xxxx_controller.rb like if we write code in account_helper.rb it's only accessible in account_controller.rb.
helper_method
is to explicitly share some methods defined in the controller to make them available for the view. This is used for any method that you need to access from both controllers and views . Like suppose we use application_controller.rb for example we add a method by name current_user like this
#application_controller.rb
helper_method :current_account private def current_account
#logged_user is method which return logged user find_by it's :session_id @current_account ||= logged_user.account if logged_user @current_accountend
Now here helper_method create a method bye name of current_account and this is share for all controller which are inherited by #application_controller.rb.
NOTE : helper_method not accessible in model.rb . Helper method use in controller only for view and if we write a method in xxxx_helper.rb then this method is only accessible in xxxx_controller.rb like if we write code in account_helper.rb it's only accessible in account_controller.rb.
No comments:
Post a Comment