# No SQL inserts -- is the controller the problem?

**URL:** <https://www.ruby-forum.com/t/no-sql-inserts-is-the-controller-the-problem/127049>\
**Category:** Rails\
**Created:** [January 24, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/no-sql-inserts-is-the-controller-the-problem/127049 "2008-01-24T16:28:21Z")\
**Posts on this page:** 2\
**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 24, 2008, 4:28pm UTC](https://www.ruby-forum.com/t/no-sql-inserts-is-the-controller-the-problem/127049/1 "2008-01-24T16:28:21Z")

</div>

The “save changes” button from [http://localhost:3000/feeds/show/1](http://localhost:3000/feeds/show/1) is  
supposed to insert data to the memberships table. A check mark is  
placed  
next to a “tag” which is unassociated with that feed, then button is  
clicked.

there are three tables: feeds, tags and a join table of memberships.  
(I  
commented out the validations.)

line 96 looks to be the “meat” of the method for the controller, where I  
suspect the problem lies:

thufir@arrakis ~/strawr $ cat app/controllers/feeds\_controller.rb -n |  
head -n 104 | tail -n 23  
82 def add\_some\_tags  
83 logger.info  
“_ **add\_some\_tags** _”  
84  
85 @feed = Feed.find(params[:id])  
86  
87 logger.info “@feed: #{@feed}”  
88  
89 @unused\_tags =  
90 Tag.find(:all) - @feed.tags  
91  
92 if @unused\_tags.any?  
93 @tags\_to\_add = @unused\_tags.select { |tag|  
94 (params[‘tag’+tag.id.to\_s][‘checked’] == ‘1’)}  
95 @tags\_to\_add.each { |tag|  
96 @feed.tags \<\< Tag.find\_or\_create\_by\_tag(params  
[:which\_tag]) unless params[:which\_tag].blank?  
97 }  
98 end  
99  
100 if @tags\_to\_add.any? and @feed.save  
101 flash[:notice] = ‘Tags have been added!’  
102 end  
103 redirect\_to :action =\> ‘show’, :id =\> @feed  
104 end  
thufir@arrakis ~/strawr $

I suspect that the above method does nothing because the log shows no  
SQL  
inserts. The “add\_some\_tags” is strictly querying the db (particularly  
I’m looking at line 54, where I’d also like to see, I believe, an  
insert):

## thufir@arrakis ~/strawr $ cat log/development.log -n | head -n 59 | tail

# n 27 33 _ **add\_some\_tags** _ 34 Feed Columns (0.001474) SHOW FIELDS FROM feeds 35 Feed Load (0.000666) SELECT \* FROM feeds WHERE (feeds.`id` = 1) 36 @feed: #Feed:0xb6fc6a50 37 Tag Load (0.000594) SELECT \* FROM tags 38 Tag Load (0.000747) SELECT tags.\* FROM tags INNER JOIN memberships ON tags.id = memberships.tag\_id WHERE ((memberships.feed\_id

# 1)) 39 Tag Columns (0.001404) SHOW FIELDS FROM tags 40 SQL (0.000230) BEGIN 41 Feed Update (0.000583) UPDATE feeds SET `feed` = ‘feed one’ WHERE `id` = 1 42 SQL (0.000342) COMMIT 43 Redirected to [http://localhost:3000/feeds/show/1](http://localhost:3000/feeds/show/1) 44 Completed in 0.18848 (5 reqs/sec) | DB: 0.00604 (3%) | 302 Found [[http://localhost/feeds/add\_some\_tags/1](http://localhost/feeds/add_some_tags/1)] 45 46 47 Processing FeedsController#show (for 127.0.0.1 at 2008-01-24 07:18:01) [GET] 48 Session ID: 98ae0df6837d8c491cfd58ecfee7c744 49 Parameters: {“action”=\>“show”, “id”=\>“1”, “controller”=\>“feeds”} 50 Feed Columns (0.001463) SHOW FIELDS FROM feeds 51 Feed Load (0.000606) SELECT \* FROM feeds WHERE (feeds.`id` = 1) 52 Rendering within layouts/feeds 53 Rendering feeds/show 54 Tag Load (0.000757) SELECT tags.\* FROM tags INNER JOIN memberships ON tags.id = memberships.tag\_id WHERE ((memberships.feed\_id

1))  
55 Tag Columns (0.001395) SHOW FIELDS FROM tags  
56 DEPRECATION WARNING: Passing :post as a link modifier is  
deprecated. Use :method =\> “post” instead. :post will be removed in  
Rails  
2.0. See [Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.](http://www.rubyonrails.org/deprecation) for details. (called  
from convert\_options\_to\_javascript! at /usr/lib/ruby/gems/1.8/gems/  
actionpack-1.13.5/lib/action\_view/helpers/url\_helper.rb:331)  
57 DEPRECATION WARNING: Passing :post as a link modifier is  
deprecated. Use :method =\> “post” instead. :post will be removed in  
Rails  
2.0. See [Ruby on Rails — A web-app framework that includes everything needed to create database-backed web applications according to the Model-View-Controller (MVC) pattern.](http://www.rubyonrails.org/deprecation) for details. (called  
from convert\_options\_to\_javascript! at /usr/lib/ruby/gems/1.8/gems/  
actionpack-1.13.5/lib/action\_view/helpers/url\_helper.rb:331)  
58 Tag Load (0.000581) SELECT \* FROM tags  
59 Completed in 0.06378 (15 reqs/sec) | Rendering: 0.04030 (63%) |  
DB: 0.00480 (7%) | 200 OK [[http://localhost/feeds/show/1](http://localhost/feeds/show/1)]  
thufir@arrakis ~/strawr $

thanks,

Thufir

[http://code.google.com/p/strawr/source](http://code.google.com/p/strawr/source)

---

<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 24, 2008, 5:14pm UTC](https://www.ruby-forum.com/t/no-sql-inserts-is-the-controller-the-problem/127049/2 "2008-01-24T17:14:23Z")

</div>

On 24 Jan 2008, at 15:27, Thufir wrote:

> line 96 looks to be the “meat” of the method for the controller,  
> where I  
> suspect the problem lies:

Install ruby-debug (gem install ruby-debug)  
run rdebug script/server

stick a call to ‘debugger’ where you think might be relevant  
Step though the code.

Fred
