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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T21:05:58+00:00 2026-05-27T21:05:58+00:00

I have a Posts model, which has many posts in many languages . It’s

  • 0

I have a Posts model, which has many posts in many languages. It’s a bit non-standard, but to illustrate:

class Post < ActiveRecord::Base
  has_one :eng_post, :dependent => :destroy         # <-- HAS_ONE!
  accepts_nested_attributes_for :eng_post, :allow_destroy => true
end

I.e. a Post has one EngPost. Whereas EngPost is defined in the model as:

class EngPost < ActiveRecord::Base
  belongs_to :post
  has_many :eng_comments, :dependent => :destroy
  accepts_nested_attributes_for :eng_comments, :allow_destroy => true
  attr_accessible :eng_comments_attributes
end

And finally, the eng_comments model is:

class EngComment < ActiveRecord::Base
  belongs_to :eng_post, :foreign_key => "eng_post_id"
end

The routes.rb defines:

resources :posts do
  resource :eng_posts
end

resource :eng_post do
  resources :eng_comments
end

resources :eng_comments

The problem – can’t render the Post with the eng_comments, I tried:

<% form_for ([@post, @post.eng_post, @post.eng_post.eng_comments.build]) do |f| %>

and tried:

<% form_for @comment do |f| %>

This results in error

undefined method `post_eng_post_eng_comments_path' for #<#<Class:0x000000067de2a8>:0x000000067c4498>

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-27T21:05:59+00:00Added an answer on May 27, 2026 at 9:05 pm

    The eng_comments also need to be nested:

    resources :posts do
       resource :eng_post do #no 's'
           resources :eng_comments
       end
    end
    
    resources :eng_posts do
         resources :eng_comments
    end
    
    resources :eng_comments
    

    If you were using
    <% form_for ([@post.eng_post, @post.eng_post.eng_comments.build]) do |f| %>
    then your current routes would work.


    ps:
    you might want to prepare all the variables in the controller (especially the eng_comment):

    def new
        @post = Post.find...
        @eng_comment = @post.eng_post.eng_comments.build
    end
    

    So that you can do:

    <% form_for ([@post, @post.eng_post, @eng_comment]) do |f| %>
    

    The advantage is that you’ll be able to use the exact same form to edit the comment (even if the comments can’t be edited in your app, I think it’s a good practice).

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

Sidebar

Related Questions

I have two models related one-to-many: a Post and a Comment : class Post(models.Model):
I have a post controller that has many comments. The post model has a
I have a model that has counter_cache enabled for an association: class Post belongs_to
I have a model called posts, and it has many attachments. The attachments model
I have a post which has many comments, and I want to display the
Okay so I have this mode: class Posts(db.Model): rand1 = db.FloatProperty() #other models here
I have a typical, Post model: class Post< ActiveRecord::Base validates_presence_of :user_id #Line 1 validates_presence_of
Say I have a model User which has_many Post children. Obviously I can access
Suppose I have a Post model which has_many Comments. I want to get the
I have a rails app which currently has 3 models: Post , User and

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.