I'm trying to do the following:
I have categories
model that has_many posts
model.
On my categories
, I use action_text
for body text content.
My issue: I would like to create a main page that lists all categories
and their posts
on a view. And jus like a regular category, I want that page to have an action_text
field for me to populate it with body text content (saved in database of course).
Then I want my routes to be as such:
match '/all' => 'pages#all_content', :via => :get, :as => :all_content
match '/:category_id' => 'pages#category', :via => :get, :as => :category
match '/:category_id/:post_id' => 'pages#post', :via => :get, :as => :post
My unsure solution: Add a boolean main
field to my category
model. That allows me to be able to populate it with content just like a regular category. And then, on my pages#all_content
, I can request the main category to have all its data.
But I'm very insecure about this solution because I think there must be a better/cleaner one. Am I wrong?
I wouldn't mix those things. Using main to get one category just for the ActionText Content sounds more like a Hack. Sounds like you like to make some kind of mini-CMS?
I would rather:
Page.find_by(key: "categories_top")
) -> If you later have different parts of the page which you need to CMSify, that approach is the relatively future-proof
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.