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

  • SEARCH
  • Home
  • 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 7876647
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T03:11:57+00:00 2026-06-03T03:11:57+00:00

In my Ruby on Rails application, each group has_many :expenses. I have nested my

  • 0

In my Ruby on Rails application, each group has_many :expenses. I have nested my routes, so expenses are entered only as child entities of their parent groups. Here’s an excerpt from routes.rb.

resources :groups do
    resources :expenses
end

I cannot figure out how to render the ‘new’ action in the case of an expense not saving when it is submitted through /groups/:group_id/expenses/new. In my expenses_controller.rb, here is how the create action is defined:

def create
    @expense = Expense.new(params[:expense])
    @expense.group_id = params[:group_id]
    if @expense.save
      redirect_to group_expense_path(@expense.group.id, @expense.id)
    else
      render 'new'
    end
end

Everything works fine if I satisty expense validation and @expense.save winds up working. However, when it fails and the code tries to render ‘new’ I get:

undefined method `expenses_path' for #<#<Class:0x007fd408b1fd58>:0x007fd408f21ca8>

So, I am assuming I have something about my nested routing wrong. How do I return the user to the new form but still display to him/her through the flash[] params the errors with the data they originally attempted to submit?

  • 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-03T03:11:58+00:00Added an answer on June 3, 2026 at 3:11 am

    The problem is that @group is not initialized

    So in your controller just do

    @expense = Expense.new(params[:expense])
    @group = Group.find(params[:group_id])
    @expense.group_id = @group.id
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a ruby on rails application and it would be nice to see
I have to to deploy a Ruby on Rails application to an tomcat application
I have created a table in my Ruby on Rails application that I am
I have built a blog application using Ruby on Rails. In the application I
I have built a blog application w/ ruby on rails and I am trying
I am developing a Ruby on Rails application with multilingual support. Now I have
If I have a Ruby on Rails application running on my Apache shared server
I'm using Ruby on Rails to develop a web application. I have a wiki
I have an Ruby on Rails 3 Heroku application, which needs to perform text
I am writing ruby on rails application, which will have 2 different users types

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.