Rails - Ability to enable / disable links in a view?

I have a UserMailer View that has several link_to:

<%= link_to('XXXXXXXX Link Title', item_url(@item, :only_path => false), :style => 'color:#5196E3;text-decoration:underline;') %>

There are several different links on the page. I would like to know if there is a way to globally set in the view to enable or disable links.

If enabled, will the above work as usual, if not for the block above, would just display the text (XXXXXXXX Link Title) and not be connected?

Any ideas other than wrapping each link_to inside an IF statement?

thank

+3
source share
3 answers

Rails already provides an assistant link_to_if...

, @some_boolean , , $some_boolean . link_to_if:

<%= link_to_if(@some_boolean, "Link Title", <url etc..>) %>

+15

, . , IF ( .)

Sean Hill: :)

ApplicationHelper:

helper_method :conditional_link

  def conditional_link(string,url)
    if true_condition
      return link_to string, url
    else 
      return string
  end

:

<%= conditional_link string, url %>
+6

else, ,

<%= link_to_if( some_boolean, "Link Title", <url etc..>) { link_to "link title", <url etc..>} %>

, , , false, .

0

Source: https://habr.com/ru/post/1783553/


All Articles