0

I'm getting this routing error on my site. I've went through other related questions and haven't found a solution yet.

No route matches {:action=>"show", :controller=>"businesses", :user_id=>3}

I have three models: user (contains login details), business (contains info related to users: one user has_one business), and business_hours (one business has many business_hours).

Here are my routes:

  devise_for :users

get "home/index"
  root :to => "home#index"

  resources :users do
    resources :businesses do
      resources :business_hours
    end
  end

Edit:

I get the error just trying to access the home page (localhost:5000). I'm currently signed in. I have run rake routes and the route seems to be there:

                   user_business GET    /users/:user_id/businesses/:id(.:format)                                  businesses#show
  • *When* do you get the error? – Dave Newton Apr 28 '13 at 14:55
  • Obvious troubleshooting tips: run `rake routes` to ensure that the `show` action is associated with the route you tried; make sure you have the `show` view in the correct directory (in this case, app/views/businesses). Also, general conventions dictate that nesting more than one resource deep is not a good idea. – aceofbassgreg Apr 28 '13 at 14:57
  • Updated the question. @aceofbassgreg What would be a better way to lay out those routes? –  Apr 28 '13 at 15:00
  • 1
    I'm not sure because I don't know your preferences for your app, but this [discussion](http://stackoverflow.com/questions/6345314/rails-3-routing-avoiding-deep-nesting) may help. – aceofbassgreg Apr 28 '13 at 15:04

1 Answers1

0

the routes which you have mentioned is expecting a forth argument which is the id of the businesses,try to pass the id of businesses it will work

user_business GET    /users/:user_id/businesses/:id(.:format) 

ideally you need to use this for index

user_businesses GET    /users/:user_id/businesses(.:format)                                      

your question is not so clear otherwise i could have given a precise answer hope this helps

yednamus
  • 582
  • 1
  • 4
  • 22
  • Thanks that solved most of the problems I'm getting. Now when I try to access businesses#new (/users/id/businesses/new) which contains a form_for @business I get this error: undefined method `businesses_path' for #<#:0x007fde829fcdc0> –  Apr 28 '13 at 15:25
  • 1
    you need to use new_user_business_path route for it – yednamus Apr 28 '13 at 15:27