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 7638295
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 31, 20262026-05-31T08:08:30+00:00 2026-05-31T08:08:30+00:00

I have a Post model: class Post < ActiveRecord::Base belongs_to :user has_many :taggings, :dependent

  • 0

I have a Post model:

class Post < ActiveRecord::Base    
  belongs_to :user

  has_many :taggings, :dependent => :destroy
  has_many :tags, :through => :taggings

  attr_writer :tag_names
  after_save :assign_tags
  before_create :init_sort_column

  def tag_names
    @tag_names || tags.map(&:name).join(" ")
  end

  private

  def assign_tags
    self.tags = []
    return if @tag_names.blank?
    @tag_names.split(" ").each do |name|
      tag = Tag.find_or_create_by_name(name)
      self.tags << tag unless tags.include?(tag)
    end
  end
end

and a Tag model:

class Tag < ActiveRecord::Base
  has_many :taggings, :dependent => :destroy  
  has_many :posts, :through => :taggings
  has_many :subscriptions
  #has_many :subscribed_users, :source => :user, :through => :subscriptions
end

This is how I list tags:

<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>

I want the user to be taken to a page displaying all the posts tagged with the tag he clicked on (like StackOverflow).

How to accomplish that?

EDIT

This is what I’ve tried:

  def tagged
    @tag = Tag.find_by_name(params[:tagged_as])
    @posts = @tag.posts.paginate
  end

I plan to display the posts in a view called tagged.html.erb

But now I’m stuck there. I’m not sure how to use :tagged_as in conjunction with link_to.

  • 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-31T08:08:31+00:00Added an answer on May 31, 2026 at 8:08 am

    You can include additional parameters in a link by passing them as options to the relevant route helper, for example:

    <%= link_to tag.name, tagged_posts_path(:tagged_as => tag.name) %>
    

    If you’re not sure which route helpers you have available, you can run rake routes to list them all (left-most column in the list).

    If you haven’t already, I’d recommend reading the Rails Guide for routes too: http://guides.rubyonrails.org/routing.html

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

Sidebar

Related Questions

I have a Post model: class Post < ActiveRecord::Base belongs_to :user has_many :taggings, :dependent
I have a Tag model: class Tag < ActiveRecord::Base has_many :taggings, :dependent => :destroy
I have a user and post model: class User < ActiveRecord::Base has_many :sent_posts, :class_name
I have the model Post: class Post < ActiveRecord::Base has_one :location, :dependent => :destroy
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names belongs_to
I have a Post model: class Post < ActiveRecord::Base attr_accessible :title, :content, :tag_names has_many
I have a typical, Post model: class Post< ActiveRecord::Base validates_presence_of :user_id #Line 1 validates_presence_of
I have the following models: class EventParticipant < ActiveRecord::Base belongs_to :event has_one :user attr_accessible

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.