I wanted to output the article list to Page # home. @ posts = Post.all data is in the Post model, controller. Not in Page model and controller. I was googled how to bring Post data to Page.
I want to bring this information to Page.
class PostsController < ApplicationController def index ＠posts = Post.all end end
Import to Page.
class Page < ApplicationRecord + extend Post::Models end
Let's define Post information on Page.
def home @posts = Post.all end
It was output.
<%= @posts.each do |p| %> <%= p.thumbnail %> <%= p.title %> <%= p.tag %> <%= p.content %> <% end %>
There is an article that explains it better. ↓ https://github.com/mc-chinju/qiita_clone/commit/262a6178d5a2eb77c6f507cf9386cb61825bfbaf https://medium.com/@yavuz255/rake-aborted-2da1233a4561 https://railsguides.jp/active_model_basics.html
Other way ↓ How to create a file in controller/concern https://programming-beginner-zeroichi.jp/articles/142
extend ActiveSupport::Concern rails concern