aymorgan
aymorgan

Reputation: 61

Create new company no longer works due to nested routes

My app has a Company model and User models, I've been working on the path/url structure and have managed to get it working how I wish using nested resources as shown in the code below.

I've used FriendlyID to added company_names and usernames to the models which all works fine.

The path now look how I want they to look:www.mydomain.com/company_name/username

routes.rb

resources :companies, :path => '/', only: [:show] do
    # constraints has been added for usernames that include a '.' 
    resources :users, :path => '/', only: [:show], :constraints => { :id => /.*/ }    
end

PROBLEM: I still need the ability to add a new company record but it will no longer work. I understand this is due to changing the routes but I don't understand how to remedy this as it keeps viewing

www.mydomain.com/companies/new as an unknown user with the username 'new'.

I'd be grateful if anyone can point me in the right direction or give me a hard with this.

Upvotes: 0

Views: 33

Answers (1)

7urkm3n
7urkm3n

Reputation: 6321

You have set only: [:show], which it means only show method is allowed.

To create a company, need to add :new and :create.

Something like this only: [:new, :create, :show]

Note:

Always after adding or changing smth in routes file, make sure to use rake routes, Rails 5 supports rails routes also.

You can see available routes!

Upvotes: 1

Related Questions