Ruby on rails RoR-一种处理为HTML和PNG的方法
我已经在我的路线上给出了这个Ruby on rails RoR-一种处理为HTML和PNG的方法,ruby-on-rails,ruby,ruby-on-rails-3,ruby-on-rails-4,Ruby On Rails,Ruby,Ruby On Rails 3,Ruby On Rails 4,我已经在我的路线上给出了这个 get '/custom_page/:page_name' => 'custom_page#load_content' 当我点击一个带有url的菜单,上面写着“/custom\u page/abc”,效果很好。。它将转到控制器以及名为load_content的视图。但问题是应用程序在终端崩溃。但它并没有显示在前端。。 我在终端中收到这些错误消息。。猜猜看 Started GET "/en/custom_page/abc" for 127.0.0.1 at 2
get '/custom_page/:page_name' => 'custom_page#load_content'
当我点击一个带有url的菜单,上面写着“/custom\u 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处理#将内容加载为HTML),然后再作为PNG处理。
(由CustomPageController处理#以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
class CustomPageController
您可以发布控制器吗code@cvibha是的,我已经更新了代码也许没有菜单项?尝试将条件更改为if@menu\u item.any?和@菜单项。第一。自定义页面。显示?