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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T04:13:20+00:00 2026-05-27T04:13:20+00:00

Hello guys I’ve a a 2 model client and meal. client.rb class Client <

  • 0

Hello guys I’ve a a 2 model client and meal.

client.rb

class Client < ActiveRecord::Base

has_many :meals
accepts_nested_attributes_for :meals

end

meal.rb

class Meal < ActiveRecord::Base
belongs_to :client
end

class Lunch < Meal
end

class Dessert < Meal
end

views/clients/_form.html.erb

    <%= simple_form_for @client do |f| %>

    <%=f.input :name %>
    <%=f.input :adress %>
    <%=f.input :telephone %>

   <%= f.simple_fields_for :meal do |m| %>
    <%=m.input :type %>
    <%end%>
  <% end %>

When I save the meal type it doesn’t appear on client’ index.html.erb(it’s blank).
What the problem is?
How can I create a client by giving him a meal type(eg.”Lunch”) with the following cotroller:

def create
  @client = Client.new(params[:client])

  respond_to do |format|
  if @client.save
    format.html { redirect_to @client, notice: 'Operation was successfully created.' }
    format.json { render json: @client, status: :created, location: @client }
  else
    format.html { render action: "new" }
    format.json { render json: @client.errors, status: :unprocessable_entity }
  end
  end
end
  • 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-27T04:13:21+00:00Added an answer on May 27, 2026 at 4:13 am

    Matter i simply have to set the column inheritance in meal.rb like this:

    class Meal < ActiveRecord::Base
    
        set_inheritance_column do
            "type" + "_id"
        end 
    
    belongs_to :client
    end
    
    class Lunch < Meal
    end
    
    class Dessert < Meal
    end
    

    So now I can select the type of meal when I create a client.
    Thanks to Anan, the solution comes from him.

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

Sidebar

Related Questions

Hello guys i have collection : public class ActionData { private int iD; public
Hello guys I have a function inside a utility class which returns the current
Hello guys I have a question regardless a old code a client needed a
Hello guys first of all apologize for asking such a simple and yet redundant
Hello guys sorry if the question looks stupid to you. i have 3 tables
Hello guys. I think it isn't possible just using PHP, but just to be
Hello can anybody solve this please I'm creating the object in the action class
Hello guys I need to pass a string array over to a setter that
Hello Guys I am trying to figure out why i am gettings this error
Hello guys i have a MSChart and i have some arrows on chart exactly

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.