I’m on the downhill side of a large project that requires an
additional integer field to be added to the tag.rb in
acts_as_taggable. I feel I have a good understanding of ActiveRecord
and have performed the correct migrations.
(As a short background for those following this thread) when one wants
to add tags to a model they call the ‘tag_with’ method that jumps into
acts_as_taggable.rb logic and attaches one or more tags to the
controlling model. The part that kills me is that this procedure
happens in such a sublime manner that I can’t see where or when the
record is created or built? Thus I can’t find a place to build and
apply a method that I would pass before the record is saved.
I’ve attempted the before_create event callback but the controller is
unable to pass a parameter to this tag.rb. It’s as though the tag.rb
instance is magically created without leaving a trail or sequence of
events that I can modify.
I was hoping I could ‘go in the front door’ and simply modify the
‘tag_with’ code such as this;
module InstanceMethods
def tag_with(list, project_id)
Tag.transaction do
taggings.destroy_all
Tag.parse(list).each do |name|
if acts_as_taggable_options[:from]
send(acts_as_taggable_options[:from]).tags.create(:name =>
name, :project_id => project_id).on(self)
else
unless Tag.find_by_name(name)
Tag.create(:name => name, :project_id =>
project_id).on(self)
end
end
end
end
end
Here is how I call this in the controller:
def create
@rateme = Rateme.new(params[:rateme])
@rateme.user = current_user
params[:project_id] = @portal.project_id.to_s
@rateme.tag_with(params[:tags], params[:project_id]) if
params[:tags]
respond_to do |format|
if @rateme.save
For some reason, Ruby still sees that this ‘tag_with’ method only
takes one argument and blasts this error:
ArgumentError in RatemesController#create
wrong number of arguments (2 for 1)
RAILS_ROOT: ./script/…/config/…
Application Trace | Framework Trace | Full Trace
#{RAILS_ROOT}/app/controllers/ratemes_controller.rb:46:in `tag_with’ "
I am happy to pay cash for this solution.
Thank you,
Kathy
[email protected]