Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
module NavigationHelpers
def path_to(page_name)
case page_name
#services
when /the list of services/
services_path
when /a new service/
new_service_path
when /edit the service named "([^"]*)"/
edit_service_path(fetch_service(name: $1))
#subscriptions
when /a new subscription for user "([^"]*)"/
new_user_subscription_path(fetch_user(username: $1))
end
end
end
World(NavigationHelpers)
module FetchHelpers
def method_missing(name, *args, &block)
clazz_name = name.to_s.sub("fetch_","").capitalize
fetch(Kernel.const_get(clazz_name), args.first)
end
private
def fetch(clazz, options)
clazz.where(options).first or
raise "No #{clazz} found for #{options.inspect}"
end
end
World(FetchHelpers)
@jonstorer

This comment has been minimized.

Copy link

@jonstorer jonstorer commented Jan 5, 2012

this line with break things because it will catch everything. you're not being selective with what you're trying to catch.

clazz_name = name.to_s.sub("fetch_","").capitalize
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.