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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:02:44+00:00 2026-05-25T03:02:44+00:00

I have a nested model form that isn’t functioning properly. The POST is to

  • 0

I have a nested model form that isn’t functioning properly. The POST is to the proper place, but then the GET reroutes me. So I’m wondering if anyone can help explain what I’m doing wrong.

I have two models: User and Profile. Code for them below:

User:

class User < ActiveRecord::Base
  attr_accessor :password, :email
  has_one :profile, :dependent => :destroy
  accepts_nested_attributes_for :profile
  ...
end

Profile:

class Profile < ActiveRecord::Base
  attr_accessible :first_name, :last_name, etc.
  belongs_to :user
  accepts_nested_attributes_for :user
  ...
end

New/Create from both models:

class UsersController < ApplicationController
  def new
    @user = User.new
    if logged_in?
      redirect_to current_user.profile
    end
  end

  def create
    @user = User.new(params[:user])
    if @user.save
      redirect_to signup_path, :notice => 'User successfully added.'
    else
      render :action => 'new'
    end
  end

class ProfilesController < ApplicationController
  def new
    @profile = Profile.new
  end

  def create
    @profile = Profile.new(params[:profile])
    if @profile.save
      redirect_to profile_path, :notice => 'User successfully added.'
    else
      render :action => 'new'
    end
  end

  def index
    @profile = current_user.profile
  end

My signup (two step process) mixes the models, so as I said I’m using a nested model form in my Users new.html.erb file. Code form_for and f.fields_for below:

<%= form_for(:user, :url => signup_path, :html => {:id => 'homepage'}) do |f| %>
<%= f.fields_for :profile do |f| %>

Now when I enter data into the form, my routes.rb file seems to POST to the proper place (/signup so profile can be filled out further), but GET routes me to /login.

Routes.rb:

match '/login' => "sessions#new", :as => "login"
match '/signup' => 'profiles#new', :as => "signup"
match 'skip/signup', :to => 'info#signupskip'
match 'skip/profiles/new', :to => 'profiles#newskip'
root :to => 'users#new'
resources :users
resources :profiles

In rails server:

Started POST "/signup" for 127.0.0.1 at Sun Aug 28 19:54:11 -0400 2011
  Processing by ProfilesController#new as HTML

Started GET "/login" for 127.0.0.1 at Sun Aug 28 19:54:11 -0400 2011
  Processing by SessionsController#new as HTML
Rendered sessions/new.html.erb within layouts/application (32.1ms)

I’m wondering if the problem is in my layouts/application file, specifically this code:

<% if logged_in? %>
  <%= render 'layouts/header_in' %>
<% else %>
  <%= render 'layouts/header_out' %>
<% end %>

Can anyone help explain to me what I’m doing wrong?

UPDATE:

I deleted the if/else argument in `layouts/application’ and it was still redirected. So I’m back to wondering what’s going on.

  • 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-05-25T03:02:44+00:00Added an answer on May 25, 2026 at 3:02 am

    I believe your problem has to do with an inherent issue (though arguably not problem) with HTTP protocol. You cannot return a redirect to a POST request. Alternatives include calling the other method from within the first controller action, or rendering the correct page directly from that action, or some mix of both.

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

Sidebar

Related Questions

I have a sign-up form that has nested associations/attributes whatever you want to call
I have been following the railscasts 'Nested Model Form Parts 1 & 2' about
I have an invoice model, that has many invoice items. I have a form
I am trying to create form that contains another model in rails. I have
I followed the instructions in Railscasts #197 http://railscasts.com/episodes/197-nested-model-form-part-2 about how to add links that
I got a form that have a nested link. The problem that the link
I have an application that uses a nested set model class to organise my
I have an application that uses a nested set model class to organise my
I have a nested model structure that looks like this: resources :users, :path =>
I keep finding that if I have nested divs inside each other, and one

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.