I think that the line with "@feed.tags <<
Tag.find_or_create_by_tag(params
[:which_tag]) unless params[:which_tag].blank?" isn''t correctly
saving
data.
What I want to happen is that the user places a checkmark on a "tag",
then clicks the button. That adds a record to the "memberships" table
with three fields:
feed_id
tag_id
membership_id
However, the db remains unchanged :(
An excerpt from
http://strawr.googlecode.com/svn/trunk/app/controllers/feeds_controller.rb
with the relevant method:
thufir@arrakis ~/strawr $
thufir@arrakis ~/strawr $ tail app/controllers/feeds_controller.rb -n 34
def add_some_tags
logger.info
"*******************************add_some_tags*******************************"
logger.info
"*******************************add_some_tags*******************************"
logger.info
"*******************************add_some_tags*******************************"
#logger.info "foo: #{@my_var}"
#logger.info "my text"
#@my_var = "something"
@feed = Feed.find(params[:id])
logger.info "@feed: #{@feed}"
@unused_tags Tag.find(:all) - @feed.tags
if @unused_tags.any?
@tags_to_add = @unused_tags.select { |tag|
(params[''tag''+tag.id.to_s][''checked'']
== ''1'')}
@tags_to_add.each { |tag|
@feed.tags << Tag.find_or_create_by_tag(params[:which_tag])
unless params[:which_tag].blank?
}
end
if @tags_to_add.any? and @feed.save
flash[:notice] = ''Tags have been added!''
end
redirect_to :action => ''show'', :id => @feed
end
end
thufir@arrakis ~/strawr $
thanks,
Thufir
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On 1/17/08, Thufir <hawat.thufir-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I think that the line with "@feed.tags << Tag.find_or_create_by_tag(params > [:which_tag]) unless params[:which_tag].blank?" isn''t correctly saving > data. > > What I want to happen is that the user places a checkmark on a "tag", > then clicks the button. That adds a record to the "memberships" table > with three fields: > > feed_id > tag_id > membership_id > > However, the db remains unchanged :( > > > > An excerpt from > http://strawr.googlecode.com/svn/trunk/app/controllers/feeds_controller.rb > with the relevant method: > > thufir@arrakis ~/strawr $ > thufir@arrakis ~/strawr $ tail app/controllers/feeds_controller.rb -n 34 > > def add_some_tags > > > logger.info > "*******************************add_some_tags*******************************" > logger.info > "*******************************add_some_tags*******************************" > logger.info > "*******************************add_some_tags*******************************" > #logger.info "foo: #{@my_var}" > #logger.info "my text" > #@my_var = "something" > > > @feed = Feed.find(params[:id]) > > logger.info "@feed: #{@feed}" > > @unused_tags > Tag.find(:all) - @feed.tags > > if @unused_tags.any? > @tags_to_add = @unused_tags.select { |tag| > (params[''tag''+tag.id.to_s][''checked''] == ''1'')} > @tags_to_add.each { |tag| > @feed.tags << Tag.find_or_create_by_tag(params[:which_tag]) > unless params[:which_tag].blank? > } > end > > if @tags_to_add.any? and @feed.save > flash[:notice] = ''Tags have been added!'' > end > redirect_to :action => ''show'', :id => @feed > end > > endPoking around in the code, I notice a few things. 1) feed has many tags through memberships, and membership.rb has some validations, perhaps these are failing. 2) In your controller code, in the method above you are using push_with_attributes, which is deprecated, you seem to be mixing hmt with the obsolete push_with_attributes. -- Rick DeNatale My blog on Ruby http://talklikeaduck.denhaven2.com/ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Jan 17, 6:20 am, "Rick DeNatale" <rick.denat...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: [...]> Poking around in the code, I notice a few things. > > 1) feed has many tags through memberships, and membership.rb has some > validations, perhaps these are failing.Yes, I was considering this and dropping the validations; I''ll do that.> 2) In your controller code, in the method above you are using > push_with_attributes, which is deprecated, you seem to be mixing hmt > with the obsolete push_with_attributes.I want to fix this regardless. I found: "push_with_attributes and concat_with_attributes on a HABTM association are deprecated. Use has_many :through with a join model instead. " http://groups.google.com/group/ror2ru/msg/d05523f76b396787 But will continue to research this. Ironically, I''m using has_many :through with a join model already. -Thufir --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---