views:

24

answers:

2

In Rails 3, when a scaffold is generated for instance for a 'Category' the will be a categories_path (and a edit_category_path(@category), ...) used in the erb views.

This is not a variable that can be found anywhere and probably is generated. However in my case, for a different entity, Article, I first generated the model and then the controller. Now when I try output an articles_path, I get a

undefined method `articles_path' for #<#:0x000001019d1be0>

I cannot even use a <%= form_for(@article) do |f| %> as this generates the same error.

What am I supposed to do?

My routings are like this:

  resources :categories do
    resources :articles
  end 
A: 

As article lives in the category scope, you need to use category_articles_path.

Toby Hede
Thanks that did it (together with vonconrad's hint)!
Jan Limpens
+1  A: 

The articles resource is within the categories scope, so the correct path to use would be category_articles_path(@category) or edit_category_articles_path(@category, @article). To do this for your form_for, try:

<%= form_for([@category, @article]) do |f| %>
vonconrad
Thanks a lot! I gave the answer tick to Toby, though, because he was first!
Jan Limpens