Skip to content

Instantly share code, notes, and snippets.

@jjgonecrypto
Created January 5, 2012 20:44
Show Gist options
  • Save jjgonecrypto/1567195 to your computer and use it in GitHub Desktop.
Save jjgonecrypto/1567195 to your computer and use it in GitHub Desktop.
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
Copy link

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