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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T09:49:50+00:00 2026-06-15T09:49:50+00:00

I have two models class Project < ActiveRecord::Base attr_accessible :created_at, :name, :status, :company_id has_many

  • 0

I have two models

class Project < ActiveRecord::Base

  attr_accessible :created_at, :name, :status, :company_id
  has_many :phases, :dependent => :destroy

end


class Phase < ActiveRecord::Base

  attr_accessible :created_at, :date_due, :name, :project_id, :status
  belongs_to :project

end

When a new phase is created, I would like to forward the user to the show project page for the project that the new phase belongs to.

I’ve tried this, as well as a few variations, but am not quite sure of the best way to write it:

def create
    @phase = Phase.new(params[:phase])

    respond_to do |format|
      if @phase.save
        redirect_to @phase.project
      else
        format.html { render action: "new" }
        format.json { render json: @phase.errors, status: :unprocessable_entity }
      end
    end
  end

Thanks!


EDIT 1

Rake Routes:

          phases GET    /phases(.:format)                  phases#index
                 POST   /phases(.:format)                  phases#create
       new_phase GET    /phases/new(.:format)              phases#new
      edit_phase GET    /phases/:id/edit(.:format)         phases#edit
           phase GET    /phases/:id(.:format)              phases#show
                 PUT    /phases/:id(.:format)              phases#update
                 DELETE /phases/:id(.:format)              phases#destroy
        projects GET    /projects(.:format)                projects#index
                 POST   /projects(.:format)                projects#create
     new_project GET    /projects/new(.:format)            projects#new
    edit_project GET    /projects/:id/edit(.:format)       projects#edit
         project GET    /projects/:id(.:format)            projects#show
                 PUT    /projects/:id(.:format)            projects#update
                 DELETE /projects/:id(.:format)            projects#destroy

EDIT 2

Updated Controller – now working. Needed to remove the respond_to block (could probably just include the different format options around the redirect, as well)

  def create
    @phase = Phase.new(params[:phase])

    if @phase.save
      redirect_to project_url(@phase.project)
    else
      render action: "new"
    end

  end
  • 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-15T09:49:51+00:00Added an answer on June 15, 2026 at 9:49 am

    Try the following:

    redirect_to project_path(@phase.project)
    

    Note: This will only work if you have your routes set up correctly.

    See the Using redirect_to section in Rails Guides for more information.

    Edit:

    The problem is probably that we aren’t passing an id to project_path(:id).

    redirect_to project_path(@phase.project.id)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the following two models: class PhotoAlbum < ActiveRecord::Base belongs_to :project has_many :photos,
I have two models, Developers and Tasks, class Developer < ActiveRecord::Base attr_accessible :address, :comment,
I have two models, Page and PageContent. class Page < ActiveRecord::Base has_many :page_contents end
I have two models: Project.rb class Project < ActiveRecord::Base belongs_to :customer end and Customer.rb
I have two models, a Project and an Action: class Project(models.Model): name = models.CharField(Project
Say I have two models in my Django project. class Project(models.Model): name = models.CharField(max_length=256)
I have two models: Company and Person class Person < ActiveRecord::Base belongs_to :company end
I have two models: class Contact(models.Model): name = models.CharField(max_length=255) class Campaign(models.Model): contact = models.ForeignKey(Contact,
I have two models: class Actor(models.Model): name = models.CharField(max_length=30, unique = True) event =
In Django, I have two models: class Product(models.Model): name = models.CharField(max_length = 50) categories

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.