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'm particularly interested in reading the data from MP3 files (ID3 tags?),
Right now my ajax posts all fire their Error events even if the action
Right now, I keep all of my projects on my laptop. I'm thinking that
Right now my ant task looks like. <javadoc sourcepath=${source} destdir=${doc}> <link href=http://java.sun.com/j2se/1.5.0/docs/api/ /> </javadoc>
Right now I have a database (about 2-3 GB) in PostgreSQL, which serves as
Right now I'm doing something like this: RewriteRule ^/?logout(/)?$ logout.php RewriteRule ^/?config(/)?$ config.php I
Right now I have an SSIS package that runs every morning and gives me
Right now I'm making an extremely simple website- about 5 pages. Question is if
Right now, I have two Eclipse projects - they both use Maven 2 for
Right now, I have code that looks something like this: Private Sub ShowReport(ByVal reportName

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.