RoR-以HTML和PNG格式处理的方法

时间:2014-05-16 06:01:49

标签: ruby-on-rails ruby ruby-on-rails-3 ruby-on-rails-4

我已经在我的路线中给出了这个。

get '/custom_page/:page_name' => 'custom_page#load_content'

当我点击一个带有url的菜单时说'/ custom_page / abc'它工作正常..它转到控制器以及名为load_content的视图。但问题是终端中的应用程序崩溃。虽然它没有在前端显示.. 我在终端上收到这些错误消息..猜猜..?

Started GET "/en/custom_page/abc" for 127.0.0.1 at 2014-05-16 11:26:25 +0530
Processing by CustomPageController#load_content as HTML
  Parameters: {"locale"=>"en", "page_name"=>"abc"}
  MenuItem Load (0.1ms)  SELECT `menu_items`.* FROM `menu_items` WHERE `menu_items`.`url` = '/custom_page/abc' ORDER BY `menu_items`.`id` ASC LIMIT 1
  CustomPage Load (0.1ms)  SELECT `custom_pages`.* FROM `custom_pages` WHERE `custom_pages`.`id` = 51 ORDER BY `custom_pages`.`id` ASC LIMIT 1
  Rendered custom_page/load_content.html.erb within layouts/calculator (0.1ms)
  User Load (0.2ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 2 ORDER BY `users`.`id` ASC LIMIT 1
  Rendered layouts/_calculator_script_top.html.erb (36.8ms)
  Rendered layouts/_calculator_header.html.erb (80.5ms)
  MenuItem Load (0.2ms)  SELECT `menu_items`.* FROM `menu_items` ORDER BY `menu_items`.`menu_priority` ASC
  Rendered layouts/_calculator_menu.html.erb (3.6ms)
  Rendered layouts/_calculator_script_bottom.html.erb (0.1ms)
Completed 200 OK in 168ms (Views: 139.1ms | ActiveRecord: 4.7ms)


Started GET "/en/custom_page/favicon.png" for 127.0.0.1 at 2014-05-16 11:26:26 +0530
Processing by CustomPageController#load_content as PNG
  Parameters: {"locale"=>"en", "page_name"=>"favicon"}
  MenuItem Load (0.2ms)  SELECT `menu_items`.* FROM `menu_items` WHERE `menu_items`.`url` = '/custom_page/favicon' ORDER BY `menu_items`.`id` ASC LIMIT 1
Completed 500 Internal Server Error in 2ms
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_request.text.erb (0.7ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.2ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_session.text.erb (0.3ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.1ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_environment.text.erb (2.0ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.1ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_backtrace.text.erb (0.1ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/_title.text.erb (0.1ms)
  Rendered /home/nithin/.rvm/gems/ruby-2.0.0-p353/gems/exception_notification-4.0.1/lib/exception_notifier/views/exception_notifier/exception_notification.text.erb (31.3ms)

似乎首先呈现正确的页面(由CustomPageController处理#load_content为HTML),然后它将处理为PNG。 (由CustomPageController处理#load_content as PNG) 我的控制器

class CustomPageController < ActionController::Base
  layout 'calculator'

  def load_content    
    page_name = (params[:page_name]).split("_").join(" ")
    session[:tab] = page_name
    @menu_item = MenuItem.where(url: "/custom_page/"+params[:page_name])
    if @menu_item.first.custom_page.present?
      @description = @menu_item.first.custom_page.description
    else
      @description = "CUSTOM PAGE NOT FOUND..."
    end         
  end

end

0 个答案:

没有答案