3

Seeing as the documentation for this gem is absolutely useless for beginners like myself (they the docs it doesn't say which code needs to go in which file), I figured I might get some better help here for my Rails 4 app instead of the official docs.

I'm not sure if acts-as-taggable-on is the best solution for my problem, but here's what I'm trying to do: I'm creating a business directory that works with tags instead of categories so that a bar/lounge can belong to both a bar, and a lounge. Perhaps someone knows a better solution instead of using acts-as-taggable-on?

There are no errors when I try to create or view the tags, but the problem is that the tags arent' being saved. When I try to view the business which has tags, it shows up empty. Same thing when I try to edit it.

This is what my model looks like:

class Business < ActiveRecord::Base
  validates :name, uniqueness: true
  acts_as_taggable
  acts_as_taggable_on :tag_list

end

The form:

<%= form_for(@business) do |f| %> 
  ...

  <div class="field">
    <%= f.label :tag_list, "Tags (seperated by commas)" %><br>
   <%= f.text_field :tag_list %>
  </div>

  ...
<% end %>

The view:

  <p>
      <strong>Tags:</strong>
      <%= @business.tag_list %>
  </p>

Anyone know what is preventing the tags from being viewed/saved? Perhaps there's better documentation out there that someone could provide.

update: I'm also using Active_Admin, which seems to be causing some problem according to Matt Boldt. After following his tutorial my problem remains unsolved.

imjp
  • 6,495
  • 10
  • 48
  • 58

3 Answers3

2

possible it is an array issue? not sure. what version of acts_as_taggable are you using?

try adding to your strong params to ask for an array.

  def business_params
      params.require(:business).permit(:xxx, :xxx, :tag_list => [])
  end
DrLulz
  • 146
  • 1
  • 9
1

I had the same problem and changing :tag_list => [] with :tag_list fixed it

I guess it depends by the type of input you use in your form, in my case was a text input

 def business_params
  params.require(:business).permit(:xxx, :xxx, :tag_list)
 end
Carlo
  • 1,184
  • 4
  • 15
  • 31
0

I was having the same problem and checked Terminal to see where the error had occurred, I got this Unpermitted parameters: tag_list

I had forgotten to add :tag_list to the strong params accepted attributes in the controller for the model I was using tags with. Try that!

kittyminky
  • 478
  • 6
  • 27