Dynamic error pages in Rails 3

In rails 3.2, it’s easier than that: Add this to config/application.rb: config.exceptions_app = self.routes That causes errors to be routed via the router. Then you just add to config/routes.rb: match “/404”, :to => “errors#not_found” I got this info from item #3 on the blog post “My five favorite hidden features in Rails 3.2” by By …

Read more

Full url for an image-path in Rails 3

You can also set CarrierWave’s asset_host config setting like this: # config/initializers/carrierwave.rb CarrierWave.configure do |config| config.storage = :file config.asset_host = ActionController::Base.asset_host end This ^ tells CarrierWave to use your app’s config.action_controller.asset_host setting, which can be defined in one of your config/envrionments/[environment].rb files. See here for more info. Or set it explicitly: config.asset_host=”http://example.com” Restart your app, and …

Read more

Rails ArgumentError: invalid %-encoding

if you don’t mind against monkeypatching Rack then create in config/initializers file (for example rack.rb) with this content: module Rack module Utils if defined?(::Encoding) def unescape(s, encoding = Encoding::UTF_8) begin URI.decode_www_form_component(s, encoding) rescue ArgumentError URI.decode_www_form_component(URI.encode(s), encoding) end end else def unescape(s, encoding = nil) begin URI.decode_www_form_component(s, encoding) rescue ArgumentError URI.decode_www_form_component(URI.encode(s), encoding) end end end module_function …

Read more