module RailsSourcePath

Constants

VERSION

Public Instance Methods

rails_source_path(default_path = root_path) click to toggle source

rails_source_path is used in View like 'cancel/back' button

# File lib/rails_source_path/rails_source_path.rb, line 17
def rails_source_path(default_path = root_path)
  session[:rails_source_path] || default_path
end
rails_source_path_entry_actions(*methods) click to toggle source

Used in controller:

rails_source_path_entry_actions :new, :edit
# File lib/rails_source_path/rails_source_path.rb, line 11
def rails_source_path_entry_actions(*methods)
  before_action :set_rails_source_path, only: methods.flatten
end
redirect_to_source(default_path = root_path) click to toggle source

used in controller when object is successfully created or updated

# File lib/rails_source_path/rails_source_path.rb, line 22
def redirect_to_source(default_path = root_path)
  path = rails_source_path(default_path)
  session.delete(:rails_source_path)
  redirect_to path
end

Private Instance Methods

set_rails_source_path() click to toggle source
# File lib/rails_source_path/rails_source_path.rb, line 30
def set_rails_source_path
  session[:rails_source_path] = begin
    URI(request.referer).request_uri
  rescue
    nil
  end
end