2016-07-13 26 views
5

Mam bardzo dziwny problem na heroku. Wygląda to tak:ActionView :: Szablon :: Błąd (niezdefiniowana metoda "cisza" dla)

= content_for :header_title do 
    = t('.header_title') 

- if @appointments.exists? 
    %table.table.table-striped.table-bordered.table-hover 
    %thead 
     %tr 
     %th= t('.id') 
     %th= t('.athena_health_id') 
     %th= t('.start_time') 
     %th= t('.duration') 
     %th= t('.provider') 
     %th= t('.created_at') 
     %th= t('.updated_at') 
    %tbody 
     = render @appointments 

    = paginate @appointments 
- else 
    %h3.text-center= t('.appointments_not_found') 
%hr/ 

Nic specjalnego. Kiedy odwiedzam stronę, która używa tego szablonu na heroku, otrzymuję:

ActionView::Template::Error (undefined method `silence' for #<Logger:0x007f7a86267a70>): 

Dane techniczne są przekazywane. Na moim lokalnym wszystko działa dobrze. Nie wiem, co się dzieje. StackTrace pokazuje, że problem jest następujący wiersz:

= paginate @appointments 

Używam Rails 5.0 i Kaminari (1.0.0.alpha). Jakieś pomysły?

Edit: W moim production.rb mam:

if ENV['RAILS_LOG_TO_STDOUT'].present? 
    config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) 
    end 

config.log_formatter = ::Logger::Formatter.new 
+1

Błąd wydaje się niezdolny znaleźć metodę "ciszy" dla klasy o nazwie "Logger". Czy twój kod ma klasę 'Logger' lub jest na końcu Heroku? – Okomikeruko

+0

Nie, moja klasa nie ma klasy rejestratora. W production.rb mam również: jeśli ENV ['RAILS_LOG_TO_STDOUT']. Present? config.logger = ActiveSupport :: TaggedLogging.new (Logger.new (STDOUT)) koniec config.log_formatter = Logger :: :: Formatter.new –

+1

Czy widzieliście [to] (https: // github. com/rails/rails/issues/20492) problem na github? Metoda 'silence' klasy' :: Logger' była przestarzała od wersji Rails4.2 i została usunięta z Rails5. – NickGnd

Odpowiedz

7

W Rails5 silence metoda została usunięta z klasy ::Logger podstawy (zobacz ten issue)

Więc zamiast przekazać instancję ::Logger, spróbuj podać instancję ActiveSupport::Logger, która ujawnia metodę silence (patrz documentation), na przykład:

config.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))

uwaga: ActiveSupport::Logger dziedziczą z klasy ::Logger bazowej obejmują moduł LoggerSilence (patrz documentation)

przykładem z mojego rails konsoli (rails5 i ruby2.3.0)

logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) 
=> #<Logger:0x007f890b8a3d10 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f890b8a2cd0 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x007f890b8a26e0 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007f890b8a2870 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f890b8a2730>>> 
logger.silence 
NoMethodError: undefined method `silence' for #<Logger:0x007f890b8a3d10> 
# ... 

logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT)) 
=> #<ActiveSupport::Logger:0x007f890bd2a028 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f890bd29fb0 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x007f890bd29f10 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007f890bd29f60 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f890bd29f38>>, @local_levels=#<Concurrent::Map:0x007f890bd29ec0 entries=0 default_proc=nil>> 
logger.silence 
LocalJumpError: no block given (yield) 
# The method exists, but I don't pass any block 
+0

Doskonała odpowiedź. –

Powiązane problemy