Rails calling action from view

帅比萌擦擦* 提交于 2019-12-05 18:47:01

I think what's happening here is that yout sidebar is being treated as a partial and your controller method is never being called. In that case I'd put the code currently contained in the sidebar controller method into either the ApplicationHelper module or the helper module of the current view, depending on whether or not you'd need to render the sidebar from other views.

You'd need to adapt the code a bit to work in a module. Rather than setting a session variable you should have the methods return the values you want.

Module SomeModule
  def blog_posts
    Blog.all :select => "created_at"
  end

  def post_months
    blog_posts.group_by { |m| m.created_at.beginning_of_month }
  end
end

Of course, that may very well need to be refactored and might not work as written, but that's the general idea I'd go with.

Good Luck.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!