2015-07-17 4 views
-1

Im usining Refinery with blog Refinery. Когда я пытаюсь вывести сообщение на домашней странице, получаю ошибкуКак вывести сообщение на главной странице с блоком Refinery

неопределенный метод `any? ' для nil: NilClas

Я думаю, что это происходит из-за разных контроллеров.

здесь код моей страницы

<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 do -%> 
            <%= 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> 

здесь контроллер для главной страницы и все другие ожидают, что блог. (Я думаю))))

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? 

    # This action is usually accessed with the root path, normally '/' 
    def home 
     render_with_templates? 
    end 

    # This action can be accessed normally, or as nested pages. 
    # Assuming a page named "mission" that is a child of "about", 
    # you can access the pages with the following URLs: 
    # 
    # GET /pages/about 
    # GET /about 
    # 
    # GET /pages/mission 
    # GET /about/mission 
    # 
    def show 
     if should_skip_to_first_child? 
     redirect_to refinery.url_for(first_live_child.url) and return 
     elsif page.link_url.present? 
     redirect_to page.link_url and return 
     elsif should_redirect_to_friendly_url? 
     redirect_to refinery.url_for(page.url), :status => 301 and 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 and trailing slashes in path, but leave internal 
     # ones for 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 

и вот контроллер блога

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 
+0

Пожалуйста, пост код контроллера. – Pavan

ответ

1

Похоже, вы получаете это в результате некоторых недостающих строк кода. Над <% if @posts.any? %> следует добавить следующее:

<% content_for :body do %> 
    <%= raw @page.content_for(Refinery::Pages.default_parts.first.to_sym) if Refinery::Pages.default_parts.any? %> 

должен исправить ваши ошибки

 Смежные вопросы

  • Нет связанных вопросов^_^