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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T00:32:04+00:00 2026-05-22T00:32:04+00:00

I have two models, Page and PageContent. class Page < ActiveRecord::Base has_many :page_contents end

  • 0

I have two models, Page and PageContent.

class Page < ActiveRecord::Base
  has_many :page_contents
end

class PageContent < ActiveRecord::Base
  belongs_to :page
end

Page has a :css_design attribute, but I want to be able to edit that attribute from my PageContent form. Any ideas?

I see a lot of accepts_nested_attributes and fields_for advice, but they don’t work, because they all seem to be for forms that are either A. Creating entire new instances of a different model from a form (for example, creating tasks from a project form), or B. Updating associated records thru the parent. I want to do the opposite- I want to update the parent’s record thru associated records.

Any help is greatly appreciated! Many thanks in advance!

–Mark


UPDATE


I have added the following to my PageContent model:

def css_design
    page ? page.css_design : nil
  end

  def css_design= (val)
    if page
      page.update_attribute 'css_design', val
    else
      @css_design = val
    end
  end

  after_create :set_page_css_design_on_create
  def set_page_css_design_on_create
    self.css_design = @css_design if page && @css_design
  end

And I have, in both my create and update actions:

@page_content.update_attributes params[:page_content]

But I’m getting:

NoMethodError (undefined method `css_design=' for #<Page:0x00000003a80338>):
  app/models/page_content.rb:13:in `css_design='
  app/controllers/page_contents_controller.rb:56:in `new'
  app/controllers/page_contents_controller.rb:56:in `create'

When I go to create the page_content for the first time. I copied and pasted this stuff straight from my files, so if you see anything weird, please let me know!

  • 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-22T00:32:05+00:00Added an answer on May 22, 2026 at 12:32 am

    Update your model with the following:

    class PageContent < ActiveRecord::Base
      belongs_to :page
      def css_design
        page ? page.css_design : nil
      end
      def css_design= (val)
        if page
          page.update_attribute 'css_design', val
        else
          @css_design = val
        end
      end
      after_create :set_page_css_design_on_create
      def set_page_css_design_on_create
        self.css_design = @css_design if page && @css_design
      end
    end
    

    Your form can now display and update the current Page’s value, even though it looks like it’s only handling PageContent:

    <%= form_for @page_content do |f| %>
      ...
      <%= f.text_field :css_design %>
      ...
    <% end %>
    

    In your controller, e.g.:

    def update
      ...
      @page_content.update_attributes params[:page_content]
      ...
    end
    
    • 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: Novel has_many :pages Page belongs_to :novel I want to list
so I have two models: class User < ActiveRecord::Base has_and_belongs_to_many :followed_courses, :class_name => Course
I have three models: class Client < ActiveRecord::Base has_many :balancesheets has_many :investment_assets, :through =>
I have two models, Article and Post that both inherit from a base model
Let's say I have two models, Classes and People. A Class might have one
I have two models, Order and UserProfile. Each Order has a ForeignKey to UserProfile,
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
I have two models: page and authors, when i choose the destroy method it

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.