KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-22 20:42 UTC
Seek brilliant Rails programmer to add one field to acts_as_taggable
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
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
s.ross
2007-Jul-22 20:46 UTC
Re: Seek brilliant Rails programmer to add one field to acts_as_taggable
did you restart the server? plugins load at start. On Jul 22, 2007, at 1:42 PM, KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote:> > 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 > KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
KathysKode-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-Jul-23 14:08 UTC
Re: Seek brilliant Rails programmer to add one field to acts_as_taggable
Mr. Ross, You hit the nail on the head. Yes. I didn''t re-start the server. Dummy me :-( Kathy On Jul 22, 3:46 pm, "s.ross" <cwdi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> did you restart the server? plugins load at start. > > On Jul 22, 2007, at 1:42 PM, KathysK...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org wrote: > > > > > > > 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 > > KathysK...-Re5JQEeQqe9DikU9e3U3fg@public.gmane.org Hide quoted text - > > - Show quoted text ---~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---