Skip to content

Instantly share code, notes, and snippets.

@pfac
Created April 17, 2015 08:43
Show Gist options
  • Save pfac/2b81d68aa02f3cfaf412 to your computer and use it in GitHub Desktop.
Save pfac/2b81d68aa02f3cfaf412 to your computer and use it in GitHub Desktop.
[Rails] Form cancel url
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