如果您在某个页面上,则隐藏按钮
Hide button if you are on some page
我需要在某些页面上显示使用 button_to
创建的两个按钮(示例:list/id1/edit
)并在所有其他页面上隐藏一个按钮(示例:list/new
)。我有这个:
= button_link t("list.save"), list_path(@list.save_id), class: "button"
= button_link t("list.cancel"), list_path(@list.hashed_id), class: "button"
如何创建 "if you are on page X show one button, else - 2 buttons"?
请查看此文档 - http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-current_page-3F
用作
current_page?('http://www.example.com/shop/checkout')
我喜欢@arjun 的回答(尤其是@RyanWilcox 的评论),尽管只是为了将其他东西扔进戒指,您还可以访问 controller_name
和 action_name
助手.. .
即
unless controller_name == 'list' && action_name == 'new'
show_the_button
end
或
- unless controller_name == 'list' && action_name == 'new'
= button_link t("list.save"), list_path(@list.save_id), class: "button"
= button_link t("list.cancel"), list_path(@list.hashed_id), class: "button"
在限制/允许某些控制器和/或操作方面可以非常灵活。
我需要在某些页面上显示使用 button_to
创建的两个按钮(示例:list/id1/edit
)并在所有其他页面上隐藏一个按钮(示例:list/new
)。我有这个:
= button_link t("list.save"), list_path(@list.save_id), class: "button"
= button_link t("list.cancel"), list_path(@list.hashed_id), class: "button"
如何创建 "if you are on page X show one button, else - 2 buttons"?
请查看此文档 - http://api.rubyonrails.org/classes/ActionView/Helpers/UrlHelper.html#method-i-current_page-3F
用作
current_page?('http://www.example.com/shop/checkout')
我喜欢@arjun 的回答(尤其是@RyanWilcox 的评论),尽管只是为了将其他东西扔进戒指,您还可以访问 controller_name
和 action_name
助手.. .
即
unless controller_name == 'list' && action_name == 'new'
show_the_button
end
或
- unless controller_name == 'list' && action_name == 'new'
= button_link t("list.save"), list_path(@list.save_id), class: "button"
= button_link t("list.cancel"), list_path(@list.hashed_id), class: "button"
在限制/允许某些控制器和/或操作方面可以非常灵活。