Fallback to index #38

Closed
wants to merge 4 commits into
from

Conversation

Projects
None yet
4 participants
Contributor

twe4ked commented Jul 6, 2012

This is actually work originally done by @ludicast but I've added a config option so you don't have to have the functionality.

Use the following in an initializer to turn the option on.

HighVoltage.setup do |config|
  config.fallback_to_index_pages = true
end

From pull #27 by @ludicast.

To help with breadcrumbs etc., I added an option for index pages. Say you visit e.g.

/pages/my_category

If high_voltage fails to locate the my_category.html view, the controller will also check:

/app/views/pages/my_category/index.html.erb

ludicast and others added some commits Oct 25, 2011

@ludicast @twe4ked ludicast added fallback for index page 49b2c79
@ludicast @twe4ked ludicast added spec for index page 86ab655
@twe4ked twe4ked Add config option to allow falling back to index pages.
Defaults to false.

Use the following in an initializer to turn the option on.

    HighVoltage.setup do |config|
      config.fallback_to_index_pages = true
    end
811c9c8
@twe4ked twe4ked Add documentation for the `fallback_to_index_pages` config option. ec6b285
Owner

mike-burns commented Jul 9, 2012

This seems like a broad stroke. How about a symlink instead?

Contributor

twe4ked commented Jul 31, 2012

@mike-burns the idea is so we can have a directory structure like:

.
├── app
│   └── views
│       └── pages
│           ├── home
│           │   └── index.html.haml
│           └── about
│               ├── team.html.haml
│               └── index.html.haml

It helps to keep things consistent and organised when you have sub pages.

Owner

mjankowski commented Aug 17, 2012

Is the benefit here just that you'd prefer that directory structure over something like this?...

app/
    views/
        pages/
        home.html
        about.html
        about/
            team.html

?

Contributor

twe4ked commented Aug 17, 2012

@mjankowski yeah, I think my example is closer to how a normal Rails app works, it seems cleaner and it allows you to organise groups of content better in my opinion. This may not be fit for everyone but it's not enabled by default so I don't see this as a problem.

Contributor

twe4ked commented Sep 26, 2012

Any further comments on this?

Owner

mike-burns commented Sep 26, 2012

I'm spiking out another possible solution right now: using an object to find the template such that you can swap the object out with another one as desired.

Contributor

twe4ked commented Sep 26, 2012

@mike-burns excellent, thanks for the update!

Owner

mike-burns commented Sep 26, 2012

I've added #42, which should allow you to do as you please. Does it seem like this will work for your situation?

Owner

mike-burns commented Sep 26, 2012

I've merged #42 and am closing this, since that will provide the functionality needed to implement this for your own system.

Please do re-open this if that's not enough or you have any questions.

Thanks!
-Mike

mike-burns closed this Sep 26, 2012

Contributor

twe4ked commented Sep 27, 2012

For anyone following along at home, this is the solution I came up with using the functionality in #42.

Thanks @mike-burns.

# app/controllers/pages_controller.rb

require 'high_voltage/page_finder' # not sure why this needs to be required here.

class PagesController < HighVoltage::PagesController
  private

  def page_finder_factory
    IndexFallbackPageFinder
  end
end
# config/routes.rb

Ennova::Application.routes.draw do
  # ...

  match '*id' => 'pages#show', :as => :page, :format => false
  root :to => 'pages#show', :id => 'home'
end
# lib/index_fallback_page_finder.rb

class IndexFallbackPageFinder < HighVoltage::PageFinder
  def find
    if ActionController::Base.new.template_exists?("pages/#{clean_path}")
      "#{content_path}#{clean_path}"
    else
      "#{content_path}#{clean_path}/index"
    end
  end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment