# Submit button has no effect on the db

**URL:** <https://www.ruby-forum.com/t/submit-button-has-no-effect-on-the-db/126315>\
**Category:** Rails\
**Created:** [January 17, 2008, 11:29am UTC](https://www.ruby-forum.com/t/submit-button-has-no-effect-on-the-db/126315 "2008-01-17T11:29:15Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 17, 2008, 11:29am UTC](https://www.ruby-forum.com/t/submit-button-has-no-effect-on-the-db/126315/1 "2008-01-17T11:29:15Z")

</div>

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](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

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 17, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/submit-button-has-no-effect-on-the-db/126315/2 "2008-01-17T15:21:01Z")

</div>

On 1/17/08, Thufir [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> tag\_id  
> thufir@arrakis ~/strawr $  
> “_ **add\_some\_tags** _”  
> Tag.find(:all) - @feed.tags  
> if @tags\_to\_add.any? and @feed.save  
> flash[:notice] = ‘Tags have been added!’  
> end  
> redirect\_to :action =\> ‘show’, :id =\> @feed  
> end
> 
> end

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.

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/](http://talklikeaduck.denhaven2.com/)

---

<div class="post-metadata">

**Author:** ![Thufir](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/t/ee7513/32.png) [@Thufir](https://www.ruby-forum.com/u/Thufir)\
**Post date:** [January 17, 2008, 10:41pm UTC](https://www.ruby-forum.com/t/submit-button-has-no-effect-on-the-db/126315/3 "2008-01-17T22:41:36Z")

</div>

On Jan 17, 6:20 am, “Rick DeNatale” [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) 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.

> 1. 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](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
