Hi Amador,

Looking at the application code you attached, your migration has the
wrong code in db/migrate/
20101208225837_create_articles_categories.rb.

Basically, in the book (https://gist.github.com/324042), we use:

t.references :category

and not

t.references :categories

What you can do to fix this is to rollback your database using: 'rake
db:rollback', until you're back before this particular migration.
Update the file, and then run 'rake db:migrate' and you should be good
to go.

I hope this fixes your problem.

Cheers,
--
Rida Al Barazi
Twitter: @rida
Blog:    http://rida.me
Book:   http://beginningrails.com

On Dec 14, 10:35 am, Amador Antonio Cuenca <[email protected]> wrote:
> Hi guys, I'm following the Beginning Rails 3 Book, I've problems with the
> many to many relationship between Article-Category, when I try to create or
> show a article.
>
> Please help me, I'm new with Rails.
>
> Regards,
>
> ActiveRecord::StatementInvalid in Articles#new
>
> Showing *I:/Labs/RailsProjects/blog/app/views/articles/_form.html.erb* where
> line *#27* raised:
>
> SQLite3::SQLException: no such column:
> articles_categories.category_id: SELECT "categories".id FROM
> "categories" INNER JOIN "articles_categories" ON "categories".id =
> "articles_categories".category_id WHERE
> ("articles_categories".article_id = NULL )
>
> Extracted source (around line *#27*):
>
> 24:       <%= f.label "Categories" %>
>
> 25:       <% for category in Category.all %>
>
> 26:         <%= check_box_tag 'article[category_ids][]', category.id,
>
> 27:           @article.category_ids.include?(category.id), :id =>
> dom_id(category) %>
>
> 28:         <%= label_tag dom_id(category), category.name, :class =>
> "check_box_label" %>
>
> 29:       <% end %>
>
> 30:     </p>
>
> Trace of template inclusion: app/views/articles/new.html.erb
>
> Rails.root: I:/Labs/RailsProjects/blog
> Application Trace <http://localhost:3000/articles/new#>
>  | Framework Trace <http://localhost:3000/articles/new#> | Full
> Trace<http://localhost:3000/articles/new#>
>
> app/views/articles/_form.html.erb:27:in `block (2 levels) in
> _app_views_articles__form_html_erb___743271537_14143752__942053146'
>
> app/views/articles/_form.html.erb:25:in `each'
>
> app/views/articles/_form.html.erb:25:in `block in
> _app_views_articles__form_html_erb___743271537_14143752__942053146'
>
> app/views/articles/_form.html.erb:1:in
> `_app_views_articles__form_html_erb___743271537_14143752__942053146'
>
> app/views/articles/new.html.erb:6:in
> `_app_views_articles_new_html_erb__987918893_24332892_280057368'
>
> app/controllers/articles_controller.rb:20:in `new'
>
> Request
>
> *Parameters*
> :
>
> None
>
> Show session dump <http://localhost:3000/articles/new#>
>
> Show env dump <http://localhost:3000/articles/new#>
> Response
>
> *Headers*
> :
>
> None
>
> --
> TSU. Amador Cuenca
>
>  blog.rar
> 184KViewDownload

-- 
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 [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to