C
C
constanto942021-01-26 01:18:09
Ruby on Rails
constanto94, 2021-01-26 01:18:09

How to wrap links in a list in ruby?

Need to wrap in a list of ul > li links. Initially, the link output code looks like this:

def links_to_hashtags(hashtags = object.hashtags)
    hashtags.map(&:to_s).map do |hashtag|
      # XXX transitional
      url = h.hashtag_page_enabled? && h.logged_out? ? h.tag_path(hashtag.downcase) : h.hashtag_friends_path(q: hashtag.downcase)
      h.link_to "##{hashtag}", url, dir: h.html_dir(hashtag)
    end.join(' ').html_safe
  end


And these are the fruits of my initiative:
def links_to_hashtags(hashtags = object.hashtags)
    hashtags.map(&:to_s).map do |hashtag|
      # XXX transitional
      url = h.hashtag_page_enabled? && h.logged_out? ? h.tag_path(hashtag.downcase) : h.hashtag_friends_path(q: hashtag.downcase)
      h.content_tag :ul, class: 'fancy' do
      h.concat h.content_tag :li, 
      h.link_to "##{hashtag}", url, dir: h.html_dir(hashtag)
    end.join(' ').html_safe
  end


Throws a number of syntax errors.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
N
N. Bekseitov, 2021-01-26
@nbekseitov

content_tag :ul, class: 'fancy' do
  hashtags.map(&:to_s).map do |hashtag|
    # XXX transitional
    url = h.hashtag_page_enabled? && h.logged_out? ? h.tag_path(hashtag.downcase) : h.hashtag_friends_path(q: hashtag.downcase)

    content_tag :li do
      link_to "##{hashtag}", url, dir: h.html_dir(hashtag)
    end
  end.join.html_safe
end

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question