ryanburnette / rcms

My learning rails project and long term Rails CMS. Not ready for primetime.
0 stars 0 forks source link

Parent/child relationship for pages #17

Open ryanburnette opened 10 years ago

ryanburnette commented 10 years ago

Pages are going to have the ability to be in a parent/child relationship. I want to be able to arrange them in a hierarchy. I wonder if Rails has a built-in way to manage this relationship, or if I should manually keep track of a parent field for pages then display accordingly.

ryanburnette commented 10 years ago

I was thinking about this and realized that the parent/child relationship is further complicated by the routing requirements.

ryanburnette commented 10 years ago

It looks like Self Joins are worth looking into for this.

Actually, nope.

ryanburnette commented 10 years ago
#in config/routes.rb
get '*', to: "my_controller#action"

#in app/controllers/my_controller.rb
def action
  path_part = path.split('/')
  valid_path = true
  path_parts.reverse.each do |part|

    if part is not parent
       render status: 404
       valid_path = false
    end
  end
  raise self
  render text: [self.inspect, path_part], headers: {"Content-Type" => "text/html"}, status: "400"
end

#NOTE
gem 'better-errors', group: :development