ruby on rails - How to output post on main page with Refinery blog -


im usining refinery refinery blog . when try output post on home page im geting error

undefined method `any?' nil:nilclas

i think happens because of different controller.

here code of page

<div class="tab-content">     <div class="tab-pane active" id="posts">        <div class="panel-default">           <div class="overflow-hidden nav nav-pills nav-stacked">                                      <% if @posts.any? %>                                     <section id="blog_posts">                                       <%= render :partial => "/refinery/blog/shared/post", :collection => @posts %>                                       <%= will_paginate @posts %>                                     </section>                                   <% else %>                                     <p><%= t('.no_blog_articles_yet') %></p>                                   <% end %>                                 <% end %>                                  <% content_for :side_body_prepend -%>                                   <%= raw @page.content_for(refinery::pages.default_parts.second.to_sym) %>                                 <% end if refinery::pages.default_parts.many? -%>                                 <%= render '/refinery/blog/shared/body_content_right' %>                                  <%= render "/refinery/content_page" %>                                 <% content_for :stylesheets, stylesheet_link_tag('refinery/blog/frontend') %>                                                      </div>                                                 </div>                                             </div> 

here controller main page , others expect blog.(i think ))) )

module refinery    module blog     class blogcontroller < ::applicationcontroller        include controllerhelper        helper :'refinery/blog/posts'       before_filter :find_page, :find_all_blog_categories        protected          def find_page           @page = refinery::page.find_by(:link_url => refinery::blog.page_url)         end     end      end      class pagescontroller < ::applicationcontroller              include pages::renderoptions      before_action :find_page, :set_canonical     before_action :error_404, :unless => :current_user_can_view_page?      # save whole page after delivery     after_action :write_cache?      # action accessed root path, '/'     def home       render_with_templates?     end      # action can accessed normally, or nested pages.     # assuming page named "mission" child of "about",     # can access pages following urls:     #     #   /pages/about     #   /about     #     #   /pages/mission     #   /about/mission     #     def show       if should_skip_to_first_child?         redirect_to refinery.url_for(first_live_child.url) , return       elsif page.link_url.present?         redirect_to page.link_url , return       elsif should_redirect_to_friendly_url?         redirect_to refinery.url_for(page.url), :status => 301 , return       end        render_with_templates?     end    protected      def requested_friendly_id       if ::refinery::pages.scope_slug_by_parent         # pick out last path component, or id if present         "#{params[:path]}/#{params[:id]}".split('/').last       else         # remove leading , trailing slashes in path, leave internal         # ones global slug scoping         params[:path].to_s.gsub(%r{\a/+}, '').presence || params[:id]       end     end      def should_skip_to_first_child?       page.skip_to_first_child && first_live_child     end      def should_redirect_to_friendly_url?       requested_friendly_id != page.friendly_id || ::refinery::pages.scope_slug_by_parent && params[:path].present? && params[:path].match(page.root.slug).nil?     end      def current_user_can_view_page?       page.live? || current_refinery_user_can_access?("refinery_pages")     end      def current_refinery_user_can_access?(plugin)       refinery_user? && current_refinery_user.authorized_plugins.include?(plugin)     end      def first_live_child       page.children.order('lft asc').live.first     end      def find_page(fallback_to_404 = true)       @page ||= case action_name                 when "home"                   refinery::page.where(:link_url => '/').first                 when "show"                   refinery::page.find_by_path_or_id(params[:path], params[:id])                 end       @page || (error_404 if fallback_to_404)     end      alias_method :page, :find_page      def set_canonical       @canonical = refinery.url_for @page.canonical if @page.present?     end      def write_cache?       if refinery::pages.cache_pages_full && !refinery_user?         cache_page(response.body, file.join('', 'refinery', 'cache', 'pages', request.path).to_s)       end     end   end end 

and here blog controller

module refinery   module blog     class blogcontroller < ::applicationcontroller        include controllerhelper        helper :'refinery/blog/posts'       before_filter :find_page, :find_all_blog_categories         protected          def find_page           @page = refinery::page.find_by(:link_url => refinery::blog.page_url)         end     end   end end 

looks you're getting result of missing lines of code. above <% if @posts.any? %> should add this:

<% content_for :body %>   <%= raw @page.content_for(refinery::pages.default_parts.first.to_sym) if refinery::pages.default_parts.any? %> 

should fix error


Comments