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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:03:37+00:00 2026-05-24T09:03:37+00:00

I am trying to build a nested model but I have a problem: In

  • 0

I am trying to build a nested model but I have a problem:

In new method in TopicController.rb

def new
  @topic = Topic.new
  @topic.message = Message.find(params[:id])
  @topic.build_comment
end

And now in create I have (1st try):

def create
  @cuser = current_facebook_user.fetch
  @topic = Topic.new(:topic)

  respond_to do |format|
    if @topic.save
      format.html { redirect_to(@topic, :notice => 'Topic was successfully created.') }
    else
      format.html { render :action => "new" }
    end
  end
end

Error for 1st try:

ActiveRecord::RecordNotFound (Couldn't find Message with ID=1 for Topic with ID=):

I also tried (2nd try):

def create
  @cuser = current_facebook_user.fetch
  @topic = Topic.new
  @topic.message = params['topic']['message_id'] #enters nil instead of the message_id
  @topic.comment = params['topic']['comment_id'] #enters nil instead of the comment_id
  @topic.user = User.find(1) #enters correct user_id

  respond_to do |format|
    if @topic.save
      format.html { redirect_to(@topic, :notice => 'Topic was successfully created.') }
    else
      format.html { render :action => "new" }
    end
  end
end

Error for second try:

No Error but Topic.message_id = nill and Topic.comment_id = nill. Those values are not assigned.

Any suggestions?

Thanks

  • 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-24T09:03:38+00:00Added an answer on May 24, 2026 at 9:03 am

    If message and comment are defined as associations in the Topic model, you shouldn’t assign IDs to them, but objects, like this:

    @topic.message = Message.find(params[:topic][:message_id])
    @topic.comment = Comment.find(params[:topic][:comment_id])
    

    This only makes sense, of course, if both message and comment have already been created.

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

Sidebar

Related Questions

I have nested attributes for a Rails model and the associations validations are failing
I have a set of nested Ant build files, and I need to control
I am trying to use a nested form but keep getting this error when
I'm trying to build a master page. What I'm trying to do is have
im trying to build a application or a method that goes through all of
I trying to build a script in linux - bash, being new to it.
i have been trying to build the Qt Driver for 2 weeks now ,
i am trying to build a network simulation with OMNet++. Problem is i dont
I have a nested model structure that looks like this: resources :users, :path =>
I am trying to set up a nested model form similar to the 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.