In my rails application, I have a create button as such
def create @client = Client.find(params[:client_id]) @inventory = @client.inventories.create(params[:inventory]) redirect_to client_path(@client) end
which, when creating the inventory (as part of the client, for example, the has_many clientβs inventory, the inventory belongs to the clients), the inventory is added to the client in the database and redirected to localhost: 3000 / client / (regardless of the Client ID)
However, I have a problem with my program, because although it does the correct redirection, the address in the address bar after clicking create is localhost: 3000 / client / 1 / inventory / 1 ... and I only want to be local: 3000 / client / 1 /. If I'm actually trying to access localhost: 3000 / client / 1 / inventoryories / 1, this gives me an error because I don't have a show for inventory.
How does this possibly make the correct redirect, but the wrong URL is displayed in my browser? By the way, this is in my route.rb, which does not seem to me a problem.
resources :clients do resources :inventories end
Why is my application behaving like this? Any taker? :]
EDIT
When I pick up rake routes, I see it. The paths of creation and destruction seem to be wrong. How can I change them?
source share