Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7648543
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T10:44:35+00:00 2026-05-31T10:44:35+00:00

Everything after @posts should persist throughout the application (Like the left sidebar you find

  • 0

Everything after @posts should persist throughout the application (Like the left sidebar you find on Facebook).

  def index
    @title = "Posts"
    default_order = "content_changed_at DESC"
    params[:order_by] ||= default_order 
    @posts = current_user.subscribed_posts.paginate(:page => params[:page],
                                                    :per_page => 5,
                                                    :order => params[:order_by])
    @subscribed_tags = current_user.subscribed_tags
    @recent_posts = current_user.posts.limit(5).order("created_at DESC")
    @tags= Tag.limit(20).order("ID asc")
    @user = current_user
  end

views/layout/_sidebar.html.erb:

    <div class="user-profile">
      <% avatar = image_tag(current_user.avatar.url(:thumb), :class => "authenticated-avatar") %>
      <%= link_to avatar, "/users/#{current_user.id}" %>
      <%= link_to "#{current_user.username}", "/users/#{current_user.id}", :class => "authenticated-username" %>
    </div>

    <%= form_for(@user, :remote => true) do |f| %>
      <div class="field">
        <%= f.label :subscribed_tag_names %><br />  
        <%= f.autocomplete_field :subscribed_tag_names, autocomplete_tag_name_posts_path, :"data-delimiter" => ' ', :class => "autocomplete_field" %>
      </div>
      <div class="actions">
        <%= f.submit :class => "user_subscribed_tag_names_submit" %>
      </div>
    <% end %>

    <div class="user-subscribed_tags">
      <% @subscribed_tags.each do |subscribed_tag| %>
        <%= link_to "#{subscribed_tag.name}(#{subscribed_tag.posts.count})", unsubscribe_tags_path(:unsubscribed_tag_name => subscribed_tag.name) %>
      <% end %>
    </div>

    <div class="user-recent-posts">
      <h4>Recent Posts</h4>
      <ul>
        <% @recent_posts.each do |recent_post| %>
          <li><%= link_to recent_post.title, recent_post %></li>
        <% end %>
      </ul>
    </div>

    <div class="top-tags">
      <% @tags.each do |tag| %>
        <span class="tag-name"><%= tag.name %></span>
        <span class="tag-count"><%= tag.posts.count %></span>
      <% end %>
    </div>
  <% end %>

Where should I place the code in the controller if I want them to persist throughout the application? (I would like to see some example code if possible).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-31T10:44:36+00:00Added an answer on May 31, 2026 at 10:44 am

    If it persists throughout the application, i.e. for every actions of all controllers, you might place it in a before_filter in the application controller.

    Add a before_filter to the application controller as :

    before_filter :find_recent_posts_and_tags
    

    And define it (as private) :

    private
    def find_recent_posts_and_tags
      # define your instance variables
    end
    

    More about filters here and here.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can anyone tell me how to write javascript code that removes everything after the
I'm just wondering how I could remove everything after a certain substring in PHP
Lets say I have the string: MyNamespace.SubNameSpace.MyClassName How do I extract just everything after
Whenever a user does something a a series of scripts are executing, after everything
How can I get everything from $string after <div class='partFive'> ?
After compiling a simple C++ project using Visual Studio 2008 on vista, everything runs
I am following the django tutorial here . I have copied everything exactly. After
It should be so simple. I've followed every tutorial and forum I could find,
I have my models setup like so: class User < ActiveRecord::Base has_many :posts, :foreign_key
Update and Solution I finally got everything working after 1. Uninstalling everything ruby-related in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.