Note that there are some explanatory texts on larger screens.

plurals
  1. POHABTM through Checkboxes Issue Rails 3
    text
    copied!<p>I've been having a problem HABTM. I'm following tutorials as I see them but no luck. Here's my code:</p> <pre><code>class Country &lt; ActiveRecord::Base has_and_belongs_to_many :videos end class Video &lt; ActiveRecord::Base has_and_belongs_to_many :countries end </code></pre> <p>Edit View:</p> <pre><code>&lt;% for country in Country.find(:all) %&gt; &lt;%= check_box_tag "video[country_ids][]", country.id, @video.countries.include?(country.id) %&gt; &lt;%= label_tag "video[country_ids][]", country.name, :for =&gt; "video[country_ids][]" %&gt;&lt;br /&gt; &lt;% end %&gt; </code></pre> <p>Show View:</p> <pre><code> &lt;% for country in @video.countries %&gt; &lt;%= country.name %&gt;&lt;br /&gt; &lt;% end %&gt; </code></pre> <p>Video Controller:</p> <pre><code> def update @video = Video.find(params[:id]) if @video.update_attributes(params[:video]) flash[:notice] = "Successfully updated video." redirect_to video_url else render :action =&gt; 'edit' end end </code></pre> <p>And the error in the log:</p> <pre><code>Started POST "/videos/2" for 127.0.0.1 at Tue Feb 08 15:01:33 -0600 2011 Processing by VideosController#update as HTML Parameters: {"commit"=&gt;"Update Video", "authenticity_token"=&gt;"6y01pmKxB+TEG0pbU6ujDsfwzqQW9eqiXBJfPHQW5+w=", "utf8"=&gt;"✓", "id"=&gt;"2", "video"=&gt;{"name"=&gt;"Video number 1", "vimeo_id"=&gt;"12341234", "country_ids"=&gt;["2", "3", "4", "11", "12", "13"]}} [1m[36mVideo Load (0.4ms)[0m [1mSELECT "videos".* FROM "videos" WHERE ("videos"."id" = 2) LIMIT 1[0m [1m[35mCountry Load (0.4ms)[0m SELECT "countries".* FROM "countries" WHERE ("countries"."id" IN (2, 3, 4, 11, 12, 13)) Completed in 35ms ActiveRecord::StatementInvalid (Could not find table 'countries_videos'): app/controllers/videos_controller.rb:31:in `update' Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (1.1ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (10.6ms) Rendered /Library/Ruby/Gems/1.8/gems/actionpack-3.0.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (16.1ms) </code></pre> <p>The Videos table and the Countries table are not joining thru the HABTM. It says it can't find the countries_videos table. What am I missing?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload