Search code examples
ruby-on-railsrefinerycms

In Refinery CMS, how can I apply page-part changes to existing pages?


I found the same question discussed in Google Groups, but the FAQ page it references is dead and the final answer looks case-specific.


Solution

  • This turned out to be pretty simple. Following the solution given in the Google Groups thread, I used the Rails console. For future reference, here's the full routine for adding a new page-part and applying to all existing pages:

    First add the new page-page(s) in your refinery pages config file. This is detailed here in the Refinery docs. In this example, I add a page-part called "epigraph":

      # Configure global page default parts
      config.default_parts =  ["Body", "Side Body", "Epigraph"]
    
      # Configure whether to allow adding new page parts
      config.new_page_parts = true
    

    Then update your view file (app\views\refinery\pages\show.html.erb if you're using the default) to include the new page-part. In my case:

       <div class="epigraph">
          <%= raw @page.content_for(:epigraph) %>
       </div>
    

    Then, from the rails console, run this map command for each new page-part you add. For my example:

    Refinery::Page.all.map {|p| p.parts.create(:title => "Epigraph", :position => 2) unless p.parts.exists?(:title => "Epigraph") }
    

    I'm assuming the position parameter specifies where to place among the tabs on the edit page and that it counts from 0. But not absolutely sure.