# Has many through button

**URL:** <https://www.ruby-forum.com/t/has-many-through-button/124624>\
**Category:** Rails\
**Created:** [December 31, 2007, 7:08am UTC](https://www.ruby-forum.com/t/has-many-through-button/124624 "2007-12-31T07:08:11Z")\
**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:** [December 31, 2007, 7:08am UTC](https://www.ruby-forum.com/t/has-many-through-button/124624/1 "2007-12-31T07:08:11Z")

</div>

I’m working on three files to get a button working:

[http://strawr.googlecode.com/svn/trunk/app/controllers/](http://strawr.googlecode.com/svn/trunk/app/controllers/)  
categories\_controller.rb

[http://strawr.googlecode.com/svn/trunk/app/helpers/application\_helper.rb](http://strawr.googlecode.com/svn/trunk/app/helpers/application_helper.rb)

[http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml](http://strawr.googlecode.com/svn/trunk/app/views/feeds/show.rhtml)

so that when navigating to [http://localhost:3000/feeds/show/2](http://localhost:3000/feeds/show/2) there’s a  
drop down list of all Category objects (this works). I want to be able  
to click on the “record” button so that it captures the feed\_id, in this  
case “2”, and also the category\_id from the drop-down list.

Currently clicking on this button as described will generate:

ActiveRecord::RecordNotFound in FeedsController#record

Couldn’t find Feed without an ID

RAILS\_ROOT: ./script/…/config/…  
Application Trace | Framework Trace | Full Trace

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active\_record/  
base.rb:1012:in `find_from_ids' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/ base.rb:419:in `find’  
/home/thufir/Desktop/strawr/app/controllers/feeds\_controller.rb:54:in  
`record’

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active\_record/  
base.rb:1012:in `find_from_ids' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/ base.rb:419:in `find’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
base.rb:1101:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ base.rb:1101:in `perform\_action\_without\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
filters.rb:696:in `call_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ filters.rb:688:in `perform\_action\_without\_benchmark’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/lib/ruby/1.8/benchmark.rb:293:in `measure’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
benchmarking.rb:66:in `perform_action_without_rescue' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ rescue.rb:83:in `perform\_action’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
base.rb:435:in `send' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ base.rb:435:in `process\_without\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
filters.rb:684:in `process_without_session_management_support' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ session_management.rb:114:in `process’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
base.rb:334:in `process' /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb:41:in `dispatch’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/webrick\_server.rb:113:in  
`handle_dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/webrick_server.rb:79:in `service’  
/usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service' /usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run’  
/usr/lib/ruby/1.8/webrick/server.rb:173:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' /usr/lib/ruby/1.8/webrick/server.rb:95:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:92:in `each' /usr/lib/ruby/1.8/webrick/server.rb:92:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:23:in `start' /usr/lib/ruby/1.8/webrick/server.rb:82:in `start’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/webrick\_server.rb:63:in  
`dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/commands/servers/webrick.rb:59 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/ dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active\_support/  
dependencies.rb:342:in `new_constants_in' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/ dependencies.rb:495:in `require’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/commands/server.rb:39  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
script/server:3

/usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active\_record/  
base.rb:1012:in `find_from_ids' /usr/lib/ruby/gems/1.8/gems/activerecord-1.15.5/lib/active_record/ base.rb:419:in `find’  
/home/thufir/Desktop/strawr/app/controllers/feeds\_controller.rb:54:in  
`record' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ base.rb:1101:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
base.rb:1101:in `perform_action_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ filters.rb:696:in `call\_filters’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
filters.rb:688:in `perform_action_without_benchmark' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/1.8/benchmark.rb:293:in `measure' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ benchmarking.rb:66:in `perform\_action\_without\_rescue’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
rescue.rb:83:in `perform_action' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ base.rb:435:in `send’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
base.rb:435:in `process_without_filters' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ filters.rb:684:in `process\_without\_session\_management\_support’  
/usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action\_controller/  
session\_management.rb:114:in `process' /usr/lib/ruby/gems/1.8/gems/actionpack-1.13.5/lib/action_controller/ base.rb:334:in `process’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/dispatcher.rb:41:in  
`dispatch' /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/webrick_server.rb:113:in `handle\_dispatch’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/webrick\_server.rb:79:in  
`service' /usr/lib/ruby/1.8/webrick/httpserver.rb:104:in `service’  
/usr/lib/ruby/1.8/webrick/httpserver.rb:65:in `run' /usr/lib/ruby/1.8/webrick/server.rb:173:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:162:in `start' /usr/lib/ruby/1.8/webrick/server.rb:162:in `start\_thread’  
/usr/lib/ruby/1.8/webrick/server.rb:95:in `start' /usr/lib/ruby/1.8/webrick/server.rb:92:in `each’  
/usr/lib/ruby/1.8/webrick/server.rb:92:in `start' /usr/lib/ruby/1.8/webrick/server.rb:23:in `start’  
/usr/lib/ruby/1.8/webrick/server.rb:82:in `start' /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/webrick_server.rb:63:in `dispatch’  
/usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/commands/servers/webrick.rb:59  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in  
`gem_original_require' /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active\_support/  
dependencies.rb:495:in `require' /usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active_support/ dependencies.rb:342:in `new\_constants\_in’  
/usr/lib/ruby/gems/1.8/gems/activesupport-1.4.4/lib/active\_support/  
dependencies.rb:495:in `require' /usr/lib/ruby/gems/1.8/gems/rails-1.2.5/lib/commands/server.rb:39 /usr/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `gem\_original\_require’  
/usr/lib/ruby/site\_ruby/1.8/rubygems/custom\_require.rb:27:in `require’  
script/server:3

Request

Parameters: None

Show session dump

* * *

flash: !map:ActionController::Flash::FlashHash {}

Response  
Headers: {“cookie”=\>[], “Cache-Control”=\>“no-cache”}

The relationship between the tables:

thufir@arrakis ~/Desktop/strawr $  
thufir@arrakis ~/Desktop/strawr $ cat app/models/category.rb  
class Category \< ActiveRecord::Base  
has\_many :tags  
has\_many :feeds, :through =\> :tags  
end  
thufir@arrakis ~/Desktop/strawr $  
thufir@arrakis ~/Desktop/strawr $ cat app/models/feed.rb  
class Feed \< ActiveRecord::Base  
has\_many :tags  
has\_many :categories, :through =\> :tags  
end  
thufir@arrakis ~/Desktop/strawr $  
thufir@arrakis ~/Desktop/strawr $ cat app/models/tag.rb  
class Tag \< ActiveRecord::Base  
belongs\_to :category  
belongs\_to :feed

end  
thufir@arrakis ~/Desktop/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:** [December 31, 2007, 1:09pm UTC](https://www.ruby-forum.com/t/has-many-through-button/124624/2 "2007-12-31T13:09:35Z")

</div>

On Mon, 31 Dec 2007 06:07:08 +0000, Thufir wrote:

> so that when navigating to [http://localhost:3000/feeds/show/2](http://localhost:3000/feeds/show/2) there’s a  
> drop down list of all Category objects (this works).

Please ignore my previous post, I’ve gone in a totally different  
direction.

While the follow tutorial is certainly dated, it’s precisely what I want  
to do:

“2. View  
To allow our web visitors to relate an expense with many tags, we are  
going to use multiple checkboxes. This is how it will look.”  
[http://jrhicks.net/96](http://jrhicks.net/96)

For my project, it’s relating a feed with many tags; otherwise I’m  
aiming  
for exactly what’s described in the PDF of the above link.

So, I used svn to roll back a bit and start over. Here’s where I’m at:

NoMethodError in Feeds#edit

Showing app/views/feeds/\_form.rhtml where line #9 raised:

You have a nil object when you didn’t expect it!  
You might have expected an instance of Array.  
The error occurred while evaluating nil.each

Extracted source (around line #9):

[http://strawr.googlecode.com/svn/trunk/app/views/feeds/\_form.rhtml](http://strawr.googlecode.com/svn/trunk/app/views/feeds/_form.rhtml)

Prior to editing \_form.rhmtl the basic CRUD actions for the db were  
vanilla, but worked.

thanks,

Thufir
