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

  • Home
  • SEARCH
  • 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 3957214
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T02:27:45+00:00 2026-05-20T02:27:45+00:00

Right now my Posts model has_many :tags, :through => :tag_joins When I add tags,

  • 0

Right now my Posts model has_many :tags, :through => :tag_joins

When I add tags, while creating a post, the tag_join records are automatically created.

Now here is what I’m trying to accomplish: While viewing the show view of posts I want to be able to add a new tag.

I tried @post.tag = Tag.new didn’t work (returns a “nomethoderror” for tag=)

So I’m trying to figure out how I can add tags and still create those joins automatically.

I am using accepts_nested_attributes etc.

UPDATE: I originally asked how to do this on the index view, but I have changed it to the show view – because I expect it to be a little easier.

  • 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-20T02:27:45+00:00Added an answer on May 20, 2026 at 2:27 am

    You’re not too far off with @posts.tags = Tag.new. Here’s a couple of ways to do it;

    @post.tags << Tag.create(params[:tag])
    @post.tags.create params[:tag]
    

    I see a couple of approaches to this problem.. One is to pass through the id of the post with the tag form using either a hidden_field or by using nested routes for tags. Then you can use that in the controller to retrieve the post and use a syntax similar to above.

    While that would work, the problem is that it’s a bit ugly.. It means your tag controller would be dealing with finding a post (which isn’t necessarily wrong, but it shouldn’t need to worry about posts. Unless tags can only be associated with posts, that is).

    The more graceful way of dealing with it would be to make the form you’re showing be a form for the post instance, not a tag. Then you could use nested attributes to create the tag as part of a post.

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

Sidebar

Related Questions

Right now I use an 'after_commit :share_all' on my posts model to call the
The application I'm building right now has problems when using HTTP post. When timeout
Users on my site can post news items. But right now, it's all honor
Right now I have an upload field while uploads files to the server. The
Right now, I have three models Post, Comment and User (using Devise ) associated
My problem right now is that a Model has a set of Validation rules
I have a Posts model and every post also contains Blocks (also a model).
Right now my ajax posts all fire their Error events even if the action
I have a Post model that has_many :comments . The question is: how can
Right now, I have: RewriteRule ^([^/\.]+)?$ index.php?id=$1 [L] to match any username at the

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.