calling a controller method from view Ruby on rails

后端 未结 4 1442
囚心锁ツ
囚心锁ツ 2021-01-02 22:22

I am very new to ruby. I have one doubt, how to call a controller method from a view.

my controller

def course_user_count
 @courses         


        
4条回答
  •  攒了一身酷
    2021-01-02 23:13

    At the top of your controller you can mark the method that you want available to your views as a helper method:

    helper_method :course_user_count
    

    Then in your view, you can call course_user_count and store the result.

    <% count = course_user_count %>
    

提交回复
热议问题