Last active
August 29, 2015 14:18
-
-
Save a2ikm/fc628593da5293b40df3 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module LinksHelper | |
def show_link_to(*records, &block) | |
options = polymorphic_path(records.flatten) | |
html_options = { class: "btn btn-info btn-sm" } | |
link_to t(:show), options, html_options, &block | |
end | |
def new_link_to(*records, &block) | |
records = records.flatten | |
model = records.pop | |
model = model.class unless model.is_a?(Class) | |
options = polymorphic_path([records, model].flatten, action: :new) | |
html_options = { class: "btn btn-success btn-sm" } | |
link_to t(:new), options, html_options, &block | |
end | |
def edit_link_to(*records, &block) | |
options = polymorphic_path(records.flatten, action: :edit) | |
html_options = { class: "btn btn-warning btn-sm" } | |
link_to t(:edit), options, html_options, &block | |
end | |
def destroy_link_to(*records, &block) | |
options = polymorphic_path(records.flatten) | |
html_options = { | |
class: "btn btn-danger btn-sm", | |
data: { confirm: t(:are_you_sure_to_destroy) }, | |
method: :delete, | |
} | |
link_to t(:destroy), options, html_options, &block | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment