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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T17:49:07+00:00 2026-05-19T17:49:07+00:00

First off, let me start by saying, I know this exact question has been

  • 0

First off, let me start by saying, I know this exact question has been asked here before. But, it was not answered and I do not want to bring up a zombie thread from over a year ago.

Second, I’m not interested in using plugins, yes, I want to re-invent the wheel. I’m writing this blog in effort to learn RoR.

I’m trying to replicate the behavior of attaching tags to a post in my Rails app.

The posts form looks like this

<%= form_for @post do |post_form| %>
  ...
  <%= render :partial => 'tags/form',
         :locals => { :form => post_form } %>
  ...
<% end %>

And the tags form as follows

<%= form.fields_for :tags do |tag_form| %>
  <div class="field">
    <%= tag_form.label :tags, 'Tags' %> <small>(comma separated)</small><br />
    <%= tag_form.text_field :tags %>
  </div>
<% end %>

The problem I’m running into is, “tags” is not a field on my Post class. My Post and Tag models have HABTM relationships with PostsTagsJoinTable in between. So, somehow I need to parse the tags text field (using string.split(‘,’), and pass the resulting tag Strings into my controller, so my controller can create and associated the tags along with the new blog post.

Are my views setup correctly? What should my controllers look like? The Post.create specifically.

Thanks!

  • 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-19T17:49:08+00:00Added an answer on May 19, 2026 at 5:49 pm

    I understand that you’re not interested in plugins, but they handle it like this:
    Class Post has method tag_list=, which does split(',') from the string and then searches and adds Tags from HABTM relation. You can define that Post#tag_list= with this:

    def tag_list=(tags)
      self.tags.clear  # clears all the relations
      tags.split(',').each do |tag|
        self.tags << Tag.find_by_title(tag)  # and assigns once again
      end
    end
    

    To provide list of tags, ie. for form field to have existing tags, do this:

    def tag_list
      self.tags.collect do |tag|
        tag.name
      end.join(',')
    end
    

    So you can now use <%= text_field_tag :post, :tag_list, :value => @post.tag_list %>.

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

Sidebar

Related Questions

First off, let me preface this question by stating that I'm really a pretty
First off, let me start by saying that I am totally new to working
First let me start of saying I know absolutely nothing about c++ and I
First let me start off by saying I do not believe I am leaking,
Let me start off by saying that I am completely new with WPF (this
First off, let me start off that I am not a .net developer. The
First off, this question is ripped out from this question. I did it because
Preface Let me start off by saying that I'm a relatively new programmer and
First off, let me say that this is not homework (I am an A-Level
First off, there's a bit of background to this issue available on my blog:

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.