`

public下文件页面引用app下的js,css以及配置404 500跳转

 
阅读更多
自己在做404跳转页面的时候把404放在public文件下,然后按照平常的方式
<%= stylesheet_link_tag "name"%>
<%= javascript_include_tag "name"%>
用上面之后就会出现在开发模式下能正常运行,但是在编译环境下就不能运行,
应该改成静态方式应用
<link href="/assets/tipsy.css" media="screen" rel="stylesheet" type="text/css" />
<script src="/assets/jquery-1.7.2.min.js" type="text/javascript"></script>
至于配置可以参考给力链接,我也复制一份,主要防止其它文档删除,难找

首先在 config/environment/development.rb中,找到下面这句代码,将其设为false
config.consider_all_requests_local  = false    # rails 4.0
或者
config.action_controller.consider_all_requests_local = false  # rails 3.0
接着修改route.rb, 在route.rb中增加下面这句:(注意:放到最后一行)
# make sure this rule is the last one
get '*path' => proc { |env| Rails.env.development? ? (raise ActionController::RoutingError, %{No route matches "#{env["PATH_INFO"]}"}) : ApplicationController.action(:render_not_found).call(env) }

然后在application_controller.rb中增加下面代码:
def self.rescue_errors
    rescue_from Exception, :with => :render_error
    rescue_from RuntimeError, :with => :render_error
    rescue_from ActiveRecord::RecordNotFound, :with => :render_not_found
    rescue_from ActionController::RoutingError, :with => :render_not_found
    rescue_from ActionController::UnknownController, :with => :render_not_found
    rescue_from ActionController::UnknownAction, :with => :render_not_found
  end

  rescue_errors unless Rails.env.development?

  def render_not_found(exception = nil)
    render :file => "/public/404.html", :status => 404
  end

  def render_error(exception = nil)
    render :file => "/public/500.html", :status => 500
  end
完成以上配置以及跳转方法

给力链接:
http://www.cnblogs.com/lmei/p/3266170.html
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics