default_url_options and rails 3

To set url options for current request use something like this in your controller: class ApplicationController < ActionController::Base def url_options { :profile => current_profile }.merge(super) end end Now, :profile => current_profile will be automerge to path/url parameters. Example routing: scope “:profile” do resources :comments end Just write: comments_path and if current_profile has set to_param to … Read more

rescue_from ActionController::RoutingError in Rails 4

In application_controller.rb add the following: # You want to get exceptions in development, but not in production. unless Rails.application.config.consider_all_requests_local rescue_from ActionController::RoutingError, with: -> { render_404 } end def render_404 respond_to do |format| format.html { render template: ‘errors/not_found’, status: 404 } format.all { render nothing: true, status: 404 } end end I usually also rescue following … Read more