Module: Thredded::UrlsHelper

Extended by:
UrlsHelper
Included in:
ApplicationController, ApplicationHelper, UrlsHelper
Defined in:
app/helpers/thredded/urls_helper.rb

Instance Method Summary collapse

Instance Method Details

#delete_post_path(post) ⇒ String

Returns path to the DELETE endpoint.

Parameters:

Returns:

  • (String)

    path to the DELETE endpoint.



71
72
73
74
75
76
77
# File 'app/helpers/thredded/urls_helper.rb', line 71

def delete_post_path(post)
  if post.private_topic_post?
    private_topic_private_post_path(post.postable, post)
  else
    messageboard_topic_post_path(post.messageboard, post.postable, post)
  end
end

#edit_post_path(post) ⇒ String

Returns path to the Edit Post page.

Parameters:

Returns:

  • (String)

    path to the Edit Post page.



61
62
63
64
65
66
67
# File 'app/helpers/thredded/urls_helper.rb', line 61

def edit_post_path(post)
  if post.private_topic_post?
    edit_private_topic_private_post_path(post.postable, post)
  else
    edit_messageboard_topic_post_path(post.messageboard, post.postable, post)
  end
end

#edit_preferences_path(messageboard = nil, params = {}) ⇒ String

Returns the path to the global or messageboard edit preferences page.

Parameters:

  • messageboard (Thredded::Messageboard, nil) (defaults to: nil)
  • params (Hash) (defaults to: {})

    additional params

Returns:

  • (String)

    the path to the global or messageboard edit preferences page.



93
94
95
# File 'app/helpers/thredded/urls_helper.rb', line 93

def edit_preferences_path(messageboard = nil, params = {})
  edit_preferences_url(messageboard, params.merge(only_path: true))
end

#edit_preferences_url(messageboard = nil, params = {}) ⇒ String

Returns the URL to the global or messageboard edit preferences page.

Parameters:

  • messageboard (Thredded::Messageboard, nil) (defaults to: nil)
  • params (Hash) (defaults to: {})

    additional params

Returns:

  • (String)

    the URL to the global or messageboard edit preferences page.



82
83
84
85
86
87
88
# File 'app/helpers/thredded/urls_helper.rb', line 82

def edit_preferences_url(messageboard = nil, params = {})
  if messageboard.try(:persisted?)
    edit_messageboard_preferences_url(messageboard, params)
  else
    edit_global_preferences_url(params)
  end
end

#post_path(post, user:, **params) ⇒ String

Returns path to the topic page with the post anchor.

Parameters:

Returns:

  • (String)

    path to the topic page with the post anchor.



55
56
57
# File 'app/helpers/thredded/urls_helper.rb', line 55

def post_path(post, user:, **params)
  post_url(post, params.merge(user: user, only_path: true))
end

#post_url(post, user:, **params) ⇒ String

Returns URL of the topic page with the post anchor.

Parameters:

Returns:

  • (String)

    URL of the topic page with the post anchor.



45
46
47
48
49
50
# File 'app/helpers/thredded/urls_helper.rb', line 45

def post_url(post, user:, **params)
  params = params.dup
  params[:anchor] ||= ActionView::RecordIdentifier.dom_id(post)
  params[:page] ||= post.private_topic_post? ? post.page : post.page(user: user)
  topic_url(post.postable, params)
end

#search_path(messageboard = nil) ⇒ String

Returns the path to the global or messageboard search.

Parameters:

Returns:

  • (String)

    the path to the global or messageboard search.



99
100
101
102
103
104
105
# File 'app/helpers/thredded/urls_helper.rb', line 99

def search_path(messageboard = nil)
  if messageboard.try(:persisted?)
    messageboard_search_path(messageboard)
  else
    messageboards_search_path
  end
end

#topic_path(topic, params = {}) ⇒ String

Returns path to the latest unread page of the given topic.

Parameters:

Returns:

  • (String)

    path to the latest unread page of the given topic.



38
39
40
# File 'app/helpers/thredded/urls_helper.rb', line 38

def topic_path(topic, params = {})
  topic_url(topic, params.merge(only_path: true))
end

#topic_url(topic, params = {}) ⇒ String

Parameters:

Returns:

  • (String)


17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'app/helpers/thredded/urls_helper.rb', line 17

def topic_url(topic, params = {})
  if params[:page] == 1
    params = params.dup
    params.delete(:page)
  end
  if topic.private?
    private_topic_url(
      topic.slug,
      params
    )
  else
    messageboard_topic_url(
      topic.messageboard.slug,
      topic.slug,
      params
    )
  end
end

#user_path(user) ⇒ String

Returns path to the user as specified by Thredded.user_path.

Parameters:

Returns:



11
12
13
# File 'app/helpers/thredded/urls_helper.rb', line 11

def user_path(user)
  Thredded.user_path(self, user)
end