Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8071219
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T13:38:51+00:00 2026-06-05T13:38:51+00:00

In my rails app, i have a create button as such def create @client

  • 0

In my rails app, 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 an inventory is created (as a part of client, ex. client has_many inventories, inventories belongs_to clients), the inventory is added to the client in the database and it redirects to localhost:3000/client/(whatever the clients ID is)

However, i’m having a problem with my program because although it does the correct redirect, the address in the address bar after i push create is localhost:3000/client/1/inventories/1… and I only want it to be localhost:3000/client/1/ . If I actually do try to access localhost:3000/client/1/inventories/1, it gives me an error because I don’t have a show for inventories.

How is it possibly doing the correct redirect, but the wrong URL is displayed in my browser? By the way, this is in my routes.rb, which does not seem like the problem to me.

 resources :clients do
    resources :inventories
 end

Why is my app behaving like this? Any takers? :]

EDIT

When I type rake routes I see this.
This
The routes for create and destroy seem wrong. How do I change them?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T13:38:52+00:00Added an answer on June 5, 2026 at 1:38 pm

    A workaround to this problem is going to inventories controller and adding

     def index
         @client = Client.find(params[:client_id])
         redirect_to client_path(@client)
     end
    

    Looks like this was the best way to handle the back button hitting these errors, it seems like you cannot control the address displayed in the address bar. At least we don’t know how.. 😛

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When I create a Rails app I am getting some errors and I have
I'm trying to have a button on the front-end of my rails app which
I have a Rails 3 app that I'm looking to create in-house analytics for.
So I have a rails app That lets users create lists and put items
I have 4 related migrations in my Rails app: First 3 migrations create one
I have a Rails 3.1 app with an image: app/assets/images/icons/button.png It seems like the
I have a Rails 3 app with a follow/unfollow button. The forms _follow.html.erb and
In a Rails app I have Sales and Salespeople: class Sale < ActiveRecord::Base belongs_to
I am creating a rails app and have used this code in one of
I want to use mysql with a rails app (I have never used mysql

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.