Created
April 17, 2015 08:43
-
-
Save pfac/2b81d68aa02f3cfaf412 to your computer and use it in GitHub Desktop.
[Rails] Form cancel url
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
def form_cancel_url(*models) | |
Rails.root unless models.empty? | |
last_idx = models.length - 1 | |
names = [] | |
models.each_index do |idx| | |
model = models[idx] | |
if model | |
name = model.class.name.tableize | |
name = name.singularize unless model.new_record? | |
names << name | |
end | |
end | |
name = names.join '_' | |
send "#{name}_url" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment