0

I have a rails model that is nested:

# app/models/frontend/item.rb
class Frontend::Item < Item
end

When I call

form_for(@frontend_item)

It tries to go to the '/frontend/items' path.

Is there a way to make it go to '/items' instead (without the inherited '/frontend')

Boris
  • 3,163
  • 5
  • 37
  • 46
  • You seem to be confusing resources and models. Models are not nested, but contained. So, your FrontEnd contains items. – Salil Jun 05 '12 at 06:16

4 Answers4

0

You might have done this already but you tried

rake routes
Benjamin
  • 2,108
  • 2
  • 26
  • 46
0

There is a very nice example of precisely what you want in the rails guides:

http://guides.rubyonrails.org/routing.html#limits-to-nesting

~Charles~

thisfeller
  • 788
  • 1
  • 5
  • 15
  • I fail to see an example of that.. note that I am nesting Models not resources in routes. – Boris Jun 04 '12 at 16:55
0

You've explicitly namespaced a Frontend::Item as a separate model from Item. Thus, a frontend_item properly routes to /frontend/items/:id.

To override that, add the following line to your routes file:

# routes.rb
match 'item/:id' => 'Frontend::Item#show'

Note that this will now conflict with the route for your Item model so you should remove that route.

Ron
  • 1,166
  • 5
  • 15
0

The solution was to create a scope section:

# config/routes.rb
scope :module => "frontend", :as => 'frontend' do
  resources :items
end
Boris
  • 3,163
  • 5
  • 37
  • 46