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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T09:19:34+00:00 2026-05-30T09:19:34+00:00

I’m following this tutorial to create tags for a model (in my case the

  • 0

I’m following this tutorial to create tags for a model (in my case the model Post):

controllers/posts_controller.rb:

  def create
    @user = current_user
    @post = @user.posts.new(params[:post])

    if @post.save
      redirect_to @post, notice: 'post was successfully created.'
    else
      render action: "new"
    end

    @post.tag!(params[:tags])
  end

views/posts/_form.html.erb:

<%= form_for(@post) do |f| %>
  <%= render 'shared/error_messages' %>
  <div class="field">
    <%= f.label :title %><br />
    <%= f.text_field :title %>
  </div>
  <div class="field">
    <%= f.label :content %><br />
    <%= f.text_area :content %>
  </div>
  <div class="field">
    <%= f.label :tags %>
    <%= f.text_field :tags, params[:tags] %>
  </div>
  <div class="actions">
    <%= f.submit %>
  </div>

views/posts/show.hmtl.erb:

<div class="tags">
  <h4>Tags:</h4>
  <%= render @post.tags %>
</div>

models/post.rb:

class Post < ActiveRecord::Base
  has_and_belongs_to_many :tags

  def tag!(tags)
    tags = tags.split(" ").map do |tag|
      Tag.find_or_create_by_name(tag)
    end
    self.tags << tags
  end
end

models/tag.rb:

class Tag < ActiveRecord::Base
  has_and_belongs_to_many :posts
end

db/migrate/(etc…)_create_tags.rb:

class CreateTags < ActiveRecord::Migration
  def change
    create_table :tags do |t|
      t.string :name
    end

    create_table :tags_posts, :id => false do | t |
      t.integer :tag_id, :post_id
    end
  end
end

Now, when I visit the posts form I get this error:

undefined method `merge' for nil:NilClass
Extracted source (around line #13):

10:   </div>
11:   <div class="field">
12:     <%= f.label :tags %>
13:     <%= f.text_field :tags, params[:tags] %>
14:   </div>
15:   <div class="actions">
16:     <%= f.submit %>

When I visit a post I get this error:

SQLite3::SQLException: no such table: posts_tags: SELECT "tags".* FROM "tags" INNER JOIN "posts_tags" ON "tags"."id" = "posts_tags"."tag_id" WHERE "posts_tags"."post_id" = 7
Extracted source (around line #24):

21: 
22:     <div class="tags">
23:       <h4>Tags:</h4>
24:       <%= render @post.tags %>
25:     </div>
26: 
27:   </div>

But I do have these tables as you can see in my schema.rb file:

 create_table "tags", :force => true do |t|
    t.string "name"
  end

  create_table "tags_posts", :id => false, :force => true do |t|
    t.integer "tag_id"
    t.integer "post_id"
  end

Any suggestions to fix this?

  • 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-30T09:19:36+00:00Added an answer on May 30, 2026 at 9:19 am

    You have the table name backwards. HABTM looks for the models alphabetically. Look at the error carefully. It says posts_tags cannot be found. You create tags_posts. So change your table name to posts_tags.

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

Sidebar

Related Questions

Basically, what I'm trying to create is a page of div tags, each has
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
this is what i have right now Drawing an RSS feed into the php,
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
I have this code: - (void)parser:(NSXMLParser *)parser foundCDATA:(NSData *)CDATABlock { NSString *someString = [[NSString
Configuring TinyMCE to allow for tags, based on a customer requirement. My config is

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.