Hi
I frequently use link_to in the context of conditional statement,
What do you think about a link helper that return nil when the condition is
false
ex:
# condtional = nil || false
%= link_to_if conditional, an_url, allow_hide: true % # = nil
or
%= link_to_if! conditional, an_url % #
You mean like these?
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to_if
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to_unless
On 17 Dec 2013, at 14:43, angelo capilleri capill...@gmail.com wrote:
Hi
I frequently use link_to in the context of conditional
No,
currently link_to_if(unless) returns the name in the false case.
Il giorno martedì 17 dicembre 2013 15:52:57 UTC+1, Zamith ha scritto:
You mean like these?
http://apidock.com/rails/ActionView/Helpers/UrlHelper/link_to_if
You can already achieve basically the same functionality with Ruby and
conditional modifiers:
%= link_to an_url,.. do %
Menu Label for admin
% end if user_role.admin? %
%= link_to an_url,.. do %
Menu Label for user
% end if user_role.user? %
%= link_to an_url,.. do %
Menu Label for gues
%
Maybe would be better if you continue to do what you are doing or define a
helper in your side.
For your use case you may have a div that can’t be seem by a normal
users, so link_to_if! will not help you, and I don’t see us adding
content_for_if or form_tag_if inside Rails.
Rafael Mendonça
What about using link_to_unless ?
2013/12/17 angelo capilleri capill...@gmail.com
Hi
I frequently use link_to in the context of conditional statement,
What do you think about a link helper that return nil when the condition
is false
ex:
# condtional = nil || false
%= link_to_if
On 17-Dec-2013, at 9:11 pm, Carlos Antonio da Silva
carlosantoniodasi...@gmail.com wrote:
%= link_to an_url,.. do %
Menu Label for admin
% end if user_role.admin? %
Although it doesn’t change things much, I would write this as:
%= link_to “Menu Label for Admin”, a_url if user_role.admin? %