I am new at rails and I am trying to have a subpost inherited from a post. A post belongs_to user and has_many subposts. I am unsure of how to create the forms and controller that will allow the post become of type subpost.
I've tried looking at tutorials but I can't grasp my head around this problem.
Something I've looked at is this. : https://devblast.com/b/single-table-inheritance-with-rails-4-part-1/
Assume that the models are correct.
Here is how the routes look like
Rails.application.routes.draw do
resources :users do
resources :post do
resources :subpost, controller: :post, type: 'Subpost'
end
end
Here is the table
create_table "posts", force: :cascade do |t|
t.text "text"
t.integer "user_id"
t.integer "post_id"
t.string "type"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.index ["post_id"], name: "index_posts_on_post_id"
t.index ["user_id"], name: "index_posts_on_user_id"
end
Form that I've been using:
<%= form_with (model: [ @user, @user.posts.build ], local: true) do |form| %>
I want the subpost to record user_id post_id and type properly on the table.