0

I have the following situation in my rails project

application.html.erb:

...
<%= render :partial => 'layouts/sidebar' %>
<%= yield %>
...

_sidebar.html.erb:

<% @groups.each do |group| %>
  <li><%= link_to group.name, "#" %></li>
<% end %>

Sidebar consists of a list of groups which doesn't change often. That's why i don't want to query the list in DB every time I go to another page in content part (yield). Is there a way how can i preserve the list throughout several pages? I KNOW about the sessions and caches, but maybe there is a better solution.

Thanks

7
  • just noticed, you can keep it static then. if its not growing sidebar ! Some case you can go for redis :) Commented Jun 20, 2017 at 17:01
  • Possible duplicate of How do I store an instance variable across multiple actions in a controller? Commented Jun 20, 2017 at 17:11
  • @AtulKhanduri I'm not interested about saving it on backend. I wrote about frontend. Commented Jun 20, 2017 at 17:25
  • Okay. So, I guess, you can store the groups in a constant file and use that constant variable in the sidebar. Commented Jun 20, 2017 at 17:29
  • The groups are not constant.. user can add or remove groups, but it doesnt happen often. Commented Jun 20, 2017 at 17:36

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.