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 8928899
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T08:33:13+00:00 2026-06-15T08:33:13+00:00

I think I am stumbling upon a rendering/redirection issue. In my rails application I

  • 0

I think I am stumbling upon a rendering/redirection issue. In my rails application I have clients who can have many projects. When I update a project I use a nested form with the form_for method, passing it a client and project instance variable, respectively.

Here is my code:

routes.rb:

resources :clients do
  resources :projects
end

projects_controller.rb

def edit
  @client = Client.find(params[:client_id])
  @project = Project.find(params[:id])
end

def update
  @project = Project.find(params[:id])

  respond_to do |format|
    if @project.update_attributes(params[:project])
      format.html { redirect_to client_project_path(@project.client, @project), notice: 'Project was successfully updated.' }
      format.json { head :no_content }
    else
      format.html { render action: "edit" } # !!this seems to be the problem
      format.json { render json: @project.errors, status: :unprocessable_entity }
    end
  end
end

views/projects/_form.html.erb:

<%= simple_form_for([@client, @project]) do |f| %>
  <%= f.error_notification %>

  <div class="form-inputs">
    <%= f.input :title %>
    <%= f.input :start_on %>
    <%= f.input :end_on %>
  </div>

  <div class="form-actions">
    <%= f.button :submit %>
  </div>
<% end %>

When I simply display the edit action, everything works fine. If I update the project with valid data, everything is fine, too. The problem occurs when I type in invalid or missing data into the form – then the “else part” of the update method is called, and the action “edit” should be rendered.

This indeed happens, but it seems to me that something is wrong either with the “edit” method or my form, because when I change render action: "edit" to redirect_to action: "edit", it does redirect me (of course without error messages so it is clearly not the desired solution, but I just wanted to test).

When “edit” is rendered, this is the error message I am getting:

undefined method `project_path'

which is only referring to the first line in my form.

What am I doing wrong here? Sorry for the long question and thanks for any help!

  • 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-15T08:33:15+00:00Added an answer on June 15, 2026 at 8:33 am

    You need to load your @client variable in the update action. Think of it this way, if you hit the else, what did the edit provide to the view, because you need just that when you render instead of redirect. Being that your resources are nested, the form_for helper needs both the client and the project.

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

Sidebar

Related Questions

Think 2 entities OneToOne mapped. Person and Car. A Person can have a Car.
I'm trying to recursively watch a directory and I'm stumbling upon a namespace issue.
Think I have an integer array like this: a[0]=60; a[1]=321; a[2]=5; now I want
I think I have a basic understanding of this, but am hoping that someone
I think this could be a very easy question for you. But I have
I remember stumbling upon a method that would tell you when a view was
It seems i keep stumbling upon strange problems. I'm working on a sort of
I've got another simple one (I think) that's stumping me. I have written a
I have inherited some code that is not working as I think it should:
This is my first time trying Pandas. I think I have a reasonable use

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.