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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T09:54:20+00:00 2026-06-13T09:54:20+00:00

I have a few models setup using STI Person < ActiveRecod….. Man Woman I’ve

  • 0

I have a few models setup using STI

Person < ActiveRecod…..

Man

Woman

I’ve specified a type field and creating a new record works fine. The sub type (Man or Woman) is succesfully saved with the record and the in the type column is the correct type.

However, when i try to update/edit the record it never calls the SQL UPDATE. update_attributes returns true. the log indicates a call to SELECT, but UPDATE is not called.

If I remove the type field from the form. and create new record it saves. but the type field is null. but then i can update the record.

any ideas or works arounds to fix this ?

controller code

# GET /persons/new
# GET /persons/new.json
def new
   @person = current_user.persons.build(params[:person])
   @person.type = params[:type]    


    respond_to do |format|
      format.html # new.html.erb
      format.json { render json: @pass }
    end
end

 # GET /persons/1/edit
 def edit
   @person = Person(params[:id])
 end

# POST /persons
# POST /persons.json
def create
@person = current_user.persons.build(params[:person])

respond_to do |format|
  if @person.save
    format.html { redirect_to @person, notice: 'Person was successfully created.' }
    format.json { render json: @person, status: :created, location: @pperson }
  else
    format.html { render action: "new" }
    format.json { render json: @person.errors, status: :unprocessable_entity }
  end
 end
end

# PUT /persons/1
# PUT /persons/1.json
def update
@person = Person.find(params[:id])

respond_to do |format|
  if @person.update_attributes(params[:person])

    format.html { redirect_to @person, notice: 'Person was successfully updated.' }
    format.json { head :no_content }
  else

    format.html { render action: "edit" }
    format.json { render json: @person.errors, status: :unprocessable_entity }
  end
end
end

when i call new it it would be for the sub class i.e

<%= link_to "New Woman", new_woman_path %>

I have routes prepared for this i.e

resources :women, :controller => "persons", :type => "Woman"
resources :men, :controller => "persons", :type => "Man"

when i call edit which is where i have the problem i.e.

<%= link_to 'Edit', edit_person_path(@person) %>

Note that if i create and edit a record in the console. it is created and updated ok.

  • 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-13T09:54:21+00:00Added an answer on June 13, 2026 at 9:54 am

    Ok, nested attributes were a red herring. The problem is with STI

    The Rails form helper guide says you can’t rely on record identification with STI.

    In the form_for we need to coearce the ids to be the base type id otherwise the edit fails

    so

    <%= form_for(@person) do |f| %>
    should be

    <%= form_for(@person.becomes(Person) do |f| %>
    if you look at the difference in the html output

    the problem html would create ids like edit_woman_fieldname when in edit mode when using .becomes we get ids like edit_room_fieldname. in whihc case it saves and updates ok

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

Sidebar

Related Questions

I have set up a few models in a simple django project. When I
I have few models - User , Teacher and TeacherLeader . class User <
I have a few models: 'Article, Video, BlogPost, News, Commodity'. Each are in their
I have a few nested view models with observable arrays and am unable to
I have quite a few libraries and models that get loaded into a controller,
I have an admin model with a few inline models included with it (see
I have my application setup with a few different partials working well. I have
I have setup for Django non-rel with Mongodb as backend. In models, I used
I have set up a few models as follows: Page Gallery Image Gallery and
I have a model that requires quite a few BooleanFields, they could be considered

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.