Sha256: 8a0c8a6cc77a44d08f8bad66febb0cb01987bf292f86a22091e4f81e8d2beeb3
Contents?: true
Size: 1.18 KB
Versions: 43
Compression:
Stored size: 1.18 KB
Contents
module Releaf::ActionController::Urls extend ActiveSupport::Concern included do helper_method :current_path, :index_path end # Returns path to redirect after successul resource create/update actions # # @return [String] path def success_path if create_another? url_for(action: :new, only_path: true) else url_for(action: :edit, id: @resource.id, only_path: true, index_path: index_path) end end # Returns index path for current request # # @return [String] path def index_path @index_path ||= resolve_index_path end def resolve_index_path # use current url if action_name == "index" current_path # use from get params elsif valid_index_path?(params[:index_path]) params[:index_path] # fallback to index view else url_for(action: :index, only_path: true) end end def valid_index_path?(value) value.present? && value.is_a?(String) && value.first == "/" end # Returns current path without internal params # # @return String def current_path @current_path ||= [request.path, (request.query_parameters.to_query if request.query_parameters.present?)].compact.join("?") end end
Version data entries
43 entries across 43 versions & 1 rubygems