Module: Releaf::ActionController::Urls

Extended by:
ActiveSupport::Concern
Included in:
Releaf::ActionController
Defined in:
app/lib/releaf/action_controller/urls.rb

Instance Method Summary collapse

Instance Method Details

#current_pathObject

Returns current path without internal params

Returns:

  • String


46
47
48
# File 'app/lib/releaf/action_controller/urls.rb', line 46

def current_path
  @current_path ||= [request.path, (request.query_parameters.to_query if request.query_parameters.present?)].compact.join("?")
end

#index_pathString

Returns index path for current request

Returns:

  • (String)

    path


22
23
24
# File 'app/lib/releaf/action_controller/urls.rb', line 22

def index_path
  @index_path ||= resolve_index_path
end

#resolve_index_pathObject


26
27
28
29
30
31
32
33
34
35
36
37
# File 'app/lib/releaf/action_controller/urls.rb', line 26

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

#success_pathString

Returns path to redirect after successul resource create/update actions

Returns:

  • (String)

    path


11
12
13
14
15
16
17
# File 'app/lib/releaf/action_controller/urls.rb', line 11

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

#valid_index_path?(value) ⇒ Boolean

Returns:

  • (Boolean)

39
40
41
# File 'app/lib/releaf/action_controller/urls.rb', line 39

def valid_index_path?(value)
  value.present? && value.is_a?(String) && value.first == "/"
end